Skip to content

Commit

Permalink
enhancements for output
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Steffmann committed May 20, 2021
1 parent 75b6bc0 commit 907f621
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions 2_Strategies/Strategy_WhatIfScenarios.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"source": [
"# Just a few days for testing\n",
"sDate = dt.datetime(2020, 1, 1)\n",
"eDate = dt.datetime(2020, 1, 10) \n",
"eDate = dt.datetime(2020, 1, 7) \n",
"\n",
"df2 = ( df.filter(df.eventtype == \"TRADE NB\").filter( df.date.between(sDate, eDate) ).filter(df.ticker == \"NFLX\") ).select(['start','open','high','low','close','volume','vwap'])\n",
"df2.show(5)"
Expand Down Expand Up @@ -512,7 +512,7 @@
" super(MyStrategy, self).next()\n",
" dt=self.datas[0].datetime.datetime(0)\n",
" r=self.data.m[dt]\n",
" print(r)\n",
" #print(r)\n",
" size=self.cerebro.strat_params['size']\n",
" threshold_PctChg=self.cerebro.strat_params['pct_chg']\n",
" \n",
Expand All @@ -524,16 +524,20 @@
" \n",
" goLong=expectedPctChg>threshold_PctChg\n",
" goShort=expectedPctChg<-threshold_PctChg\n",
" print(\"expectedPctChg=%s,goLong=%s,goShort=%s\" % (expectedPctChg,goLong,goShort))\n",
" #print(\"expectedPctChg=%s,goLong=%s,goShort=%s\" % (expectedPctChg,goLong,goShort))\n",
" \n",
" if not self.position:\n",
" if goLong:\n",
" print(\"%s:%s x BUY @ %.2f\" % (dt,size,r['close']))\n",
" self.buy(size=size) # Go long\n",
" else:\n",
" print(\"%s:%s x SELL @ %.2f\" % (dt,size,r['close']))\n",
" self.sell(size=size) # Go short\n",
" elif self.position.size>0 and goShort:\n",
" print(\"%s:%s x SELL @ %.2f\" % (dt,size*2,r['close']))\n",
" self.sell(size=size*2)\n",
" elif self.position.size<0 and goLong: \n",
" elif self.position.size<0 and goLong: \n",
" print(\"%s:%s x BUY @ %.2f\" % (dt,size*2,r['close']))\n",
" self.buy(size=size*2)"
]
},
Expand Down Expand Up @@ -616,7 +620,7 @@
}
],
"metadata": {
"instance_type": "ml.t3.medium",
"instance_type": "ml.m5.large",
"kernelspec": {
"display_name": "FinSpace PySpark (finspace-sparkmagic-f9c1f/latest)",
"language": "python",
Expand Down

0 comments on commit 907f621

Please sign in to comment.