https://wiki.haskell.org/api.php?action=feedcontributions&user=Jn&feedformat=atomHaskellWiki - User contributions [en]2020-01-22T13:54:32ZUser contributionsMediaWiki 1.27.4https://wiki.haskell.org/index.php?title=Programming_performance/JN_K&diff=11873Programming performance/JN K2007-03-09T18:08:59Z<p>Jn: </p>
<hr />
<div>Submission in K. Start to finish time: 17 minutes.<br><br />
RaymondH showed me his, so this might not be entirely originial.<br><br />
I tried not to look at any of the K solutions.<br><br />
<br />
<blockquote><pre><br />
/ parse quotes<br />
D:|1_*(" F ";" ")0:`:gspc.txt<br />
<br />
/ Cash and Portfolio (price -> quantity)<br />
C:10000.00; P:(`u#0#0.)!0#0.<br />
<br />
/ Trading strategy<br />
T:{if[~.97<x%y; P[x]+:(b:C%10)%x; C-:b]; C+:x*+/P p:p@&~1.06>x%p:!P; P[p]:0.}<br />
<br />
/ run strategy on each pair (current and previous) of prices<br />
(*D)T':D;<br />
<br />
/ Sell off remaining<br />
C+:+/.:[P]**|D<br />
</pre></blockquote></div>Jnhttps://wiki.haskell.org/index.php?title=Programming_performance/JN_K&diff=11870Programming performance/JN K2007-03-09T18:04:09Z<p>Jn: </p>
<hr />
<div>Submission in K. Start to finish time: 17 minutes.<br><br />
RaymondH showed me his, so this might not be entirely originial.<br><br />
I tried not to look at any of the K solutions.<br><br />
<br />
<blockquote><pre><br />
/ parse quotes<br />
D:|1_*(" F ";" ")0:`:/tmp/gspc.txt<br />
<br />
/ Cash and Portfolio (price -> quantity)<br />
C:10000.00; P:(`u#0#0.)!0#0.<br />
<br />
/ Trading strategy<br />
T:{if[~.97<x%y; P[x]+:(b:C%10)%x; C-:b]; C+:x*+/P p:p@&~1.06>x%p:!P; P[p]:0.}<br />
<br />
/ run strategy on each pair (current and previous) of prices<br />
(*D)T':D;<br />
<br />
/ Sell off remaining<br />
C+:+/.:[P]**|D<br />
</pre></blockquote></div>Jnhttps://wiki.haskell.org/index.php?title=Programming_performance&diff=11869Programming performance2007-03-09T18:03:41Z<p>Jn: added JN entry</p>
<hr />
<div>[[Category:Code]]<br />
<br />
== Goal ==<br />
<br />
The goal is to measure how long it takes to implement solutions to a standard problem in your programming language of choice and to see the various approaches different programmers take when implementing the solution. The goal isn't to finish the problem as quickly as possible but to rather to get some realistic measurements on programming speed and approaches.<br />
<br />
== Submitted results ==<br />
<br />
{| border="1" cellspacing="0" cellpadding="5" align="center" <br />
! Data<br />
! Language<br />
! Experience<br />
! Time<br />
|-<br />
| [[Programming performance/TimN Haskell]]<br />
| Haskell<br />
| Intermediate<br />
| 45min?<br />
|-<br />
| [[Programming performance/TimN Python]]<br />
| Python<br />
| Advanced<br />
| 30min?<br />
|-<br />
| [[Programming performance/Magnus Haskell]]<br />
| Haskell<br />
| Intermediate<br />
| 25min<br />
|-<br />
| [[Programming performance/kc5tja Forth]]<br />
| Forth<br />
| Advanced<br />
| 3.7hr<br />
|-<br />
| [[Programming performance/Apter K]] (added by kc5tja)<br />
| K<br />
| Advanced<br />
| 15min?<br />
|-<br />
| [[Programming performance/hay.steve Python]]<br />
| Python<br />
| Beginner<br />
| 1.5hr<br />
|-<br />
| [[Programming performance/JasonWoof Ruby]]<br />
| Ruby<br />
| Beginner<br />
| 50 minutes<br />
|-<br />
| [[Programming performance/RaymondH Python]]<br />
| Python<br />
| Advanced<br />
| 20-25 minutes<br />
|-<br />
| [[Programming performance/ArthurVanLeeuwen Haskell]]<br />
| Haskell<br />
| Advanced<br />
|25 minutes<br />
|-<br />
| [[Programming performance/JasonWoof gforth]]<br />
| gforth<br />
| Experienced<br />
|102 minutes<br />
|-<br />
| [[Programming performance/ScottN MySQL]]<br />
| MySQL<br />
| Advanced<br />
|23 minutes<br />
|-<br />
| [[Programming performance/JN K]]<br />
| K<br />
| Intermediate<br />
|17 minutes<br />
|}<br />
<br />
<br />
<br />
<br />
== Instructions ==<br />
<br />
Implement a program that computes the solution to the following problem in your language of choice. Measure how long it took you to make your initial implementation. Post the code and the amount of time it took. Please submit only your time and code for your first implementation in a given language. If you have implemented a solution previously in another language please mention that. You may submit further refinements of your solution or new solutions on the same page as your initial submission but the primary goals is to measure your initial solution and the amount of time required. If you wish, you may look at other solutions but it is preferable that you do not.<br />
<br />
Submit your entry by creating a wiki page with your code, your time, the language used and a note about how comfortable you are with this language. If you relied on any help, such as reading other solutions, please state what sort of help you made use of. Please make just one page per participant per language. You may include any comments, refinements or alternate programs on this same page.<br />
<br />
<br />
<br />
<br />
== Problem ==<br />
<br />
Simulate the following strategy on the GSPC data set:<br />
<br />
* Whenever the closing cost is down 3% or more from the previous closing cost, buy shares with 10% of current cash.<br />
* Whenever the closing cost is up 6% or more from the original purchase price, sell back the full amount of stock purchased at that price.<br />
* Sell off any remaining assets after the last day.<br />
<br />
<br />
Run the strategy on the provided data starting with $10,000.00 in cash and no holdings.<br />
* All purchases are made at the closing cost.<br />
* Fractional shares may be purchased.<br />
* Fractional pennies may be used.<br />
* Do not simulate any trading costs, interest dividends or taxes.<br />
* Percent change is 100 percent times the change (new price minus old price) divided by the old price.<br />
<br />
<br />
=== Data ===<br />
<br />
The http://www.thenewsh.com/gspc.txt file contains the test data. Any lines not starting with a hash sign ("#") contain valid data. Data is in space seperated columns. Each line represents one day's data with most recent date first. The first column contains the date and the last column contains the closing price. The number of columns is always the same.<br />
<br />
<br />
=== Results ===<br />
<br />
Display the amount of cash held after executing the strategy. A mode that displays each buy and sell by date is useful, but optional.</div>Jn