Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This doesn't really sound like several days of work :p unless I'm missing something.</p> <pre><code># returns array of percentage gain per period def percentage_gain(array) initial = array[0] after = 0 percentage_gain = [] 1.upto(array.size-1).each do |i| after = array[i] percentage_gain &lt;&lt; (after - initial)/initial*100 initial = after end percentage_gain end # returns array of amount gain $ per period def amount_gain(array) initial = array[0] after = 0 amount_gain = [] 1.upto(array.size-1).each do |i| after = array[i] percentage_gain &lt;&lt; (after - initial) initial = after end amount_gain end # returns the maximum amount gain found in the array def max_amount_gain(array) amount_gain(array).max end # returns the maximum percentage gain found in the array def max_percentage_gain(array) percentage_gain(array).max end # returns the maximum potential gain you could've made by shortselling constantly. # i am basically adding up the amount gained when you would've hit profit. # on days the stock loses value, i don't add them. def max_potential_amount_gain(array) initial = array[0] after = 0 max_potential_gain = 0 1.upto(array.size-1).each do |i| after = array[i] if after - initial &gt; 0 max_potential_gain += after - initial end initial = after end amount_gain end array = [15.42, 16.42, 17.36, 16.22, 14.72, 13.95, 14.73, 13.76, 12.88, 13.51, 12.67, 11.11, 10.04, 10.38, 10.14, 7.72, 7.46, 9.41, 11.39, 9.7, 12.67, 18.42, 18.44, 18.03, 17.48, 19.6, 19.57, 18.48, 17.36, 18.03, 18.1, 19.07, 21.02, 20.77, 19.92, 18.71, 20.29, 22.36, 22.38, 22.39, 22.94, 23.5, 21.66, 22.06, 21.07, 19.86, 19.49, 18.79, 18.16, 17.24, 17.74, 18.41, 17.56, 17.24, 16.04, 16.05, 15.4, 15.77, 15.68, 16.29, 15.23, 14.51, 14.05, 13.28, 13.49, 13.12, 14.33, 13.67, 13.13, 12.45, 12.48, 11.58, 11.52, 11.2, 10.46, 12.24, 11.62, 11.43, 10.96, 10.63, 10.19, 10.03, 9.7, 9.64, 9.16, 8.96, 8.49, 8.16, 8.0, 7.86, 8.08, 8.02, 7.67, 8.07, 8.37, 8.35, 8.82, 8.58, 8.47, 8.42, 7.92, 7.77, 7.79, 7.6, 7.18, 7.44, 7.74, 7.47, 7.63, 7.21, 7.06, 6.9, 6.84, 6.96, 6.93, 6.49, 6.38, 6.69, 6.49, 6.76] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload