H1

Download data

Run:

appcfg.py download_data --url=http://binary-trading.appspot.com/remoteapi --filename=runs.csv --kind="Run" --config_file=config.yaml

Import dependencies



In [189]:
import numpy as np
import pandas as pd
%matplotlib inline
from matplotlib import pyplot as plt

Load Data



In [190]:
df = pd.read_csv('runs.csv')
print df.columns


Index([u'payout', u'time_frame', u'ended_at', u'is_win', u'probability', u'profit', u'stake_parent', u'created_at', u'stake', u'parent_run', u'updated_at', u'binary_ref', u'trade_base', u'currency', u'step', u'profit_parent', u'key', u'trade_aim', u'is_finished', u'profit_net', u'stake_net'], dtype='object')

Profitability

Win/loss ratio


In [191]:
df['is_win'].hist()


Out[191]:
<matplotlib.axes._subplots.AxesSubplot at 0x129d52790>
Actual profit

Shows the cumulative profit


In [203]:
print df[df['step'] > 8]
df['profit'].cumsum().plot()


       payout  time_frame             ended_at is_win  probability  profit  \
296    510.95           5  2015-03-25T05:20:12   True          NaN  254.95   
1419   916.72          10  2015-03-27T12:26:27   True     0.656217  315.15   
2264  1051.54          40  2015-03-31T09:56:12  False     0.563780 -592.84   
2270  1000.71          40  2015-03-31T10:16:10   True     0.568695  431.61   
2278   802.62          40  2015-03-31T10:36:32   True     0.524369  381.75   

      stake_parent           created_at   stake                  parent_run  \
296            NaN  2015-03-25T05:15:13  256.00  2015-03-25 04:30:13.439040   
1419        170.03  2015-03-27T12:16:30  601.57  2015-03-27 12:06:09.834710   
2264        273.11  2015-03-31T09:16:14  592.84  2015-03-31 08:35:30.057900   
2270        252.37  2015-03-31T09:36:12  569.10  2015-03-31 08:55:47.755710   
2278        219.74  2015-03-31T09:56:34  420.87  2015-03-31 09:16:09.880530   

        ...      trade_base  currency step profit_parent  \
296     ...          payout    EURUSD    9       -255.00   
1419    ...     directional    EURUSD    9       -317.62   
2264    ...     directional    EURUSD    9       -458.00   
2270    ...     directional    EURUSD    9       -433.25   
2278    ...     directional    EURUSD    9       -381.64   

                             key  trade_aim is_finished profit_net stake_net  \
296   2015-03-25 05:15:12.248760     higher        True      -0.05       NaN   
1419  2015-03-27 12:16:27.326670      lower        True      -2.47    771.60   
2264  2015-03-31 09:16:12.421990     higher        True   -1050.84    865.95   
2270  2015-03-31 09:36:10.002680     higher        True      -1.64    821.47   
2278  2015-03-31 09:56:32.104910     higher        True       0.11    640.61   

           roi  
296   0.995898  
1419  0.523879  
2264 -1.000000  
2270  0.758408  
2278  0.907050  

[5 rows x 22 columns]
Out[203]:
<matplotlib.axes._subplots.AxesSubplot at 0x12adbf950>

ROI



In [193]:
df['roi'] = df['profit'] / df['stake']
#print df[df['profit'] > 20]
#print df[df['roi'] < -1]
print df[['payout', 'stake', 'profit', 'roi']].tail()


      payout  stake  profit  roi
2718    1.00   0.56     NaN  NaN
2719    1.00   0.56     NaN  NaN
2720   65.92  43.33     NaN  NaN
2721    1.00   0.56     NaN  NaN
2722    1.00   0.56     NaN  NaN

Time Frames


In [194]:
tf_roi = df[['roi']].groupby(df['time_frame']) # .sort('roi', ascending=False)
#tf_roi
#tf_roi.plot()
#tf_roi.plot(subplots=True)
# tf_roi.plot(secondary_y=('roi', 'count'))
tf_roi.mean().plot(kind='bar', subplots=True, grid=False, yerr=tf_roi.std())
#tf_roi.plot(kind='kde', subplots=True, grid=False)
#tf_roi.boxplot()
tf_roi.count().plot(kind='bar', subplots=True, grid=False)


Out[194]:
array([<matplotlib.axes._subplots.AxesSubplot object at 0x129e53510>], dtype=object)

Trade Base


In [195]:
grouped = df.groupby('trade_base')
grouped['roi'].mean().plot(kind='barh', yerr=grouped['roi'].std())


Out[195]:
<matplotlib.axes._subplots.AxesSubplot at 0x129ec3ed0>

Trade Base & Aim

Goal:

  • Want to see the ROI per selection
  • Want to see the avg steps per selection (reduce risk)

In [196]:
grouped = df.groupby(['trade_base', 'trade_aim'])
#for name, group in grouped:
#    print(name)
#    print(group['roi'].tail())
#print grouped['roi'].mean()
#print grouped['roi'].std()
grouped['roi'].mean().plot(kind='bar', yerr=grouped['roi'].std())


Out[196]:
<matplotlib.axes._subplots.AxesSubplot at 0x12a304810>

In [197]:
grouped['step'].mean().plot(kind='bar', yerr=grouped['step'].std())


Out[197]:
<matplotlib.axes._subplots.AxesSubplot at 0x12a3d33d0>

Step

ROI by step

Goal:

  • confirm visualisation should be useless

In [198]:
grouped = df.groupby(['step'])
grouped['roi'].mean().plot(kind='bar', grid=False, yerr=grouped['roi'].std())


Out[198]:
<matplotlib.axes._subplots.AxesSubplot at 0x12a48ef90>

Count by step

Goal:

  • to establish probability of ruin

In [199]:
vals = df['step'].value_counts()
print vals
#print vals.index.values
#print vals.values
coeffs = np.polyfit(vals.index.values, vals.values, 2)
poly = np.poly1d(coeffs)
print poly
vals.plot(kind='bar')
#plt.plot(vals.index.values, [0.5**(x+1) for x in vals.index.values])


1    1491
2     645
3     316
4     144
5      62
6      31
7      19
8      10
9       5
dtype: int64
       2
42.83 x - 570.9 x + 1801
Out[199]:
<matplotlib.axes._subplots.AxesSubplot at 0x12a946c90>

In [200]:
df_last = df[df['is_win'] == True]
vals = df_last['step'].value_counts()
print vals
vals.plot(kind='bar')


1    821
2    325
3    170
4     81
5     30
6     11
7      9
9      4
8      4
dtype: int64
Out[200]:
<matplotlib.axes._subplots.AxesSubplot at 0x12a9aee50>

Stake by step

Goal:

  • show the volatility per step
  • used in bankroll management

In [201]:
grouped = df.groupby(['step'])
grouped['stake'].mean().plot(kind='bar', yerr=grouped['stake'].std())


Out[201]:
<matplotlib.axes._subplots.AxesSubplot at 0x12abf8390>

Stake of total stake by step


In [202]:
grouped = df.groupby(['step'])
grouped['stake_net'].mean().plot(kind='bar', yerr=grouped['stake_net'].std())


Out[202]:
<matplotlib.axes._subplots.AxesSubplot at 0x12ad62cd0>

In [ ]: