mirror of
https://github.com/bspeice/speice.io
synced 2024-12-22 08:38:09 -05:00
1 line
28 KiB
JavaScript
1 line
28 KiB
JavaScript
"use strict";(self.webpackChunkspeice_io=self.webpackChunkspeice_io||[]).push([["4833"],{76171:function(e,s,t){t.r(s),t.d(s,{assets:function(){return o},contentTitle:function(){return r},default:function(){return m},frontMatter:function(){return l},metadata:function(){return n},toc:function(){return c}});var n=t(93071),a=t(85893),i=t(50065);let l={slug:"2016/02/profitability-using-the-investment-formula",title:"Profitability using the investment formula",date:new Date("2016-02-26T12:00:00.000Z"),authors:["bspeice"],tags:[]},r=void 0,o={authorsImageUrls:[void 0]},c=[{value:"Theoretical Justification",id:"theoretical-justification",level:2},{value:"Running a simulation",id:"running-a-simulation",level:2},{value:"And now the interesting part",id:"and-now-the-interesting-part",level:2},{value:"Summary and plans for the next post",id:"summary-and-plans-for-the-next-post",level:2}];function h(e){let s={a:"a",annotation:"annotation",code:"code",h2:"h2",img:"img",li:"li",math:"math",mfrac:"mfrac",mi:"mi",mn:"mn",mo:"mo",mrow:"mrow",p:"p",pre:"pre",semantics:"semantics",span:"span",strong:"strong",ul:"ul",...(0,i.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.p,{children:"After developing a formula to guide our investing, how do we actually evaluate its performance in the real world?"}),"\n",(0,a.jsxs)(s.p,{children:["I've previously talked about crafting an ",(0,a.jsx)(s.a,{href:"/2016/02/guaranteed-money-maker",children:"Investment Formula"})," that would guarantee making money if you could predict which direction the stock market was going to go. This is going to be the first in a series of posts trying to flesh out what an actual investment strategy based on this formula would look like."]}),"\n",(0,a.jsxs)(s.p,{children:["But first, the formula doesn't take into account two very important things: ",(0,a.jsx)(s.strong,{children:"leverage"}),", and the ",(0,a.jsx)(s.strong,{children:"number of days invested"}),". That's why I want to set up what I'm going to call the ",(0,a.jsx)(s.strong,{children:"Profitability Score"}),"."]}),"\n",(0,a.jsx)(s.p,{children:"The definition is going to be very simple:"}),"\n",(0,a.jsxs)(s.ul,{children:["\n",(0,a.jsxs)(s.li,{children:[(0,a.jsxs)(s.span,{className:"katex",children:[(0,a.jsx)(s.span,{className:"katex-mathml",children:(0,a.jsx)(s.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,a.jsxs)(s.semantics,{children:[(0,a.jsx)(s.mrow,{children:(0,a.jsx)(s.mi,{children:"p"})}),(0,a.jsx)(s.annotation,{encoding:"application/x-tex",children:"p"})]})})}),(0,a.jsx)(s.span,{className:"katex-html","aria-hidden":"true",children:(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"0.625em",verticalAlign:"-0.1944em"}}),(0,a.jsx)(s.span,{className:"mord mathnormal",children:"p"})]})})]}),": Profit made once you exit the investment"]}),"\n",(0,a.jsxs)(s.li,{children:[(0,a.jsxs)(s.span,{className:"katex",children:[(0,a.jsx)(s.span,{className:"katex-mathml",children:(0,a.jsx)(s.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,a.jsxs)(s.semantics,{children:[(0,a.jsx)(s.mrow,{children:(0,a.jsx)(s.mi,{children:"i"})}),(0,a.jsx)(s.annotation,{encoding:"application/x-tex",children:"i"})]})})}),(0,a.jsx)(s.span,{className:"katex-html","aria-hidden":"true",children:(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"0.6595em"}}),(0,a.jsx)(s.span,{className:"mord mathnormal",children:"i"})]})})]}),": Initial investment into the asset"]}),"\n",(0,a.jsxs)(s.li,{children:[(0,a.jsxs)(s.span,{className:"katex",children:[(0,a.jsx)(s.span,{className:"katex-mathml",children:(0,a.jsx)(s.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,a.jsxs)(s.semantics,{children:[(0,a.jsx)(s.mrow,{children:(0,a.jsx)(s.mi,{children:"m"})}),(0,a.jsx)(s.annotation,{encoding:"application/x-tex",children:"m"})]})})}),(0,a.jsx)(s.span,{className:"katex-html","aria-hidden":"true",children:(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"0.4306em"}}),(0,a.jsx)(s.span,{className:"mord mathnormal",children:"m"})]})})]}),": Maximum investment in the asset"]}),"\n",(0,a.jsxs)(s.li,{children:[(0,a.jsxs)(s.span,{className:"katex",children:[(0,a.jsx)(s.span,{className:"katex-mathml",children:(0,a.jsx)(s.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,a.jsxs)(s.semantics,{children:[(0,a.jsxs)(s.mrow,{children:[(0,a.jsx)(s.mi,{children:"l"}),(0,a.jsx)(s.mo,{children:"="}),(0,a.jsx)(s.mi,{children:"m"}),(0,a.jsx)(s.mi,{mathvariant:"normal",children:"/"}),(0,a.jsx)(s.mi,{children:"i"})]}),(0,a.jsx)(s.annotation,{encoding:"application/x-tex",children:"l = m / i"})]})})}),(0,a.jsxs)(s.span,{className:"katex-html","aria-hidden":"true",children:[(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"0.6944em"}}),(0,a.jsx)(s.span,{className:"mord mathnormal",style:{marginRight:"0.01968em"},children:"l"}),(0,a.jsx)(s.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,a.jsx)(s.span,{className:"mrel",children:"="}),(0,a.jsx)(s.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,a.jsx)(s.span,{className:"mord mathnormal",children:"m"}),(0,a.jsx)(s.span,{className:"mord",children:"/"}),(0,a.jsx)(s.span,{className:"mord mathnormal",children:"i"})]})]})]}),": The maximum leverage of an investment, as the ratio of maximum invested to initial investment"]}),"\n",(0,a.jsxs)(s.li,{children:[(0,a.jsxs)(s.span,{className:"katex",children:[(0,a.jsx)(s.span,{className:"katex-mathml",children:(0,a.jsx)(s.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,a.jsxs)(s.semantics,{children:[(0,a.jsx)(s.mrow,{children:(0,a.jsx)(s.mi,{children:"d"})}),(0,a.jsx)(s.annotation,{encoding:"application/x-tex",children:"d"})]})})}),(0,a.jsx)(s.span,{className:"katex-html","aria-hidden":"true",children:(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"0.6944em"}}),(0,a.jsx)(s.span,{className:"mord mathnormal",children:"d"})]})})]}),": The number of days it takes to turn a profit"]}),"\n"]}),"\n",(0,a.jsx)(s.p,{children:(0,a.jsxs)(s.span,{className:"katex",children:[(0,a.jsx)(s.span,{className:"katex-mathml",children:(0,a.jsx)(s.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,a.jsxs)(s.semantics,{children:[(0,a.jsxs)(s.mrow,{children:[(0,a.jsx)(s.mi,{children:"s"}),(0,a.jsx)(s.mo,{children:"="}),(0,a.jsxs)(s.mfrac,{children:[(0,a.jsxs)(s.mrow,{children:[(0,a.jsx)(s.mn,{children:"1000"}),(0,a.jsx)(s.mi,{children:"p"})]}),(0,a.jsxs)(s.mrow,{children:[(0,a.jsx)(s.mi,{children:"i"}),(0,a.jsx)(s.mo,{stretchy:"false",children:"("}),(0,a.jsx)(s.mi,{children:"l"}),(0,a.jsx)(s.mo,{children:"+"}),(0,a.jsx)(s.mi,{children:"d"}),(0,a.jsx)(s.mo,{stretchy:"false",children:")"})]})]}),(0,a.jsx)(s.mo,{children:"="}),(0,a.jsxs)(s.mfrac,{children:[(0,a.jsxs)(s.mrow,{children:[(0,a.jsx)(s.mn,{children:"1000"}),(0,a.jsx)(s.mi,{children:"p"})]}),(0,a.jsxs)(s.mrow,{children:[(0,a.jsx)(s.mi,{children:"m"}),(0,a.jsx)(s.mo,{children:"+"}),(0,a.jsx)(s.mi,{children:"i"}),(0,a.jsx)(s.mo,{children:"\u22C5"}),(0,a.jsx)(s.mi,{children:"d"})]})]})]}),(0,a.jsx)(s.annotation,{encoding:"application/x-tex",children:"s = \\frac{1000 p}{i(l + d)} = \\frac{1000 p}{m + i\\cdot d}"})]})})}),(0,a.jsxs)(s.span,{className:"katex-html","aria-hidden":"true",children:[(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"0.4306em"}}),(0,a.jsx)(s.span,{className:"mord mathnormal",children:"s"}),(0,a.jsx)(s.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,a.jsx)(s.span,{className:"mrel",children:"="}),(0,a.jsx)(s.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"1.4172em",verticalAlign:"-0.52em"}}),(0,a.jsxs)(s.span,{className:"mord",children:[(0,a.jsx)(s.span,{className:"mopen nulldelimiter"}),(0,a.jsx)(s.span,{className:"mfrac",children:(0,a.jsxs)(s.span,{className:"vlist-t vlist-t2",children:[(0,a.jsxs)(s.span,{className:"vlist-r",children:[(0,a.jsxs)(s.span,{className:"vlist",style:{height:"0.8972em"},children:[(0,a.jsxs)(s.span,{style:{top:"-2.655em"},children:[(0,a.jsx)(s.span,{className:"pstrut",style:{height:"3em"}}),(0,a.jsx)(s.span,{className:"sizing reset-size6 size3 mtight",children:(0,a.jsxs)(s.span,{className:"mord mtight",children:[(0,a.jsx)(s.span,{className:"mord mathnormal mtight",children:"i"}),(0,a.jsx)(s.span,{className:"mopen mtight",children:"("}),(0,a.jsx)(s.span,{className:"mord mathnormal mtight",style:{marginRight:"0.01968em"},children:"l"}),(0,a.jsx)(s.span,{className:"mbin mtight",children:"+"}),(0,a.jsx)(s.span,{className:"mord mathnormal mtight",children:"d"}),(0,a.jsx)(s.span,{className:"mclose mtight",children:")"})]})})]}),(0,a.jsxs)(s.span,{style:{top:"-3.23em"},children:[(0,a.jsx)(s.span,{className:"pstrut",style:{height:"3em"}}),(0,a.jsx)(s.span,{className:"frac-line",style:{borderBottomWidth:"0.04em"}})]}),(0,a.jsxs)(s.span,{style:{top:"-3.4461em"},children:[(0,a.jsx)(s.span,{className:"pstrut",style:{height:"3em"}}),(0,a.jsx)(s.span,{className:"sizing reset-size6 size3 mtight",children:(0,a.jsxs)(s.span,{className:"mord mtight",children:[(0,a.jsx)(s.span,{className:"mord mtight",children:"1000"}),(0,a.jsx)(s.span,{className:"mord mathnormal mtight",children:"p"})]})})]})]}),(0,a.jsx)(s.span,{className:"vlist-s",children:"\u200B"})]}),(0,a.jsx)(s.span,{className:"vlist-r",children:(0,a.jsx)(s.span,{className:"vlist",style:{height:"0.52em"},children:(0,a.jsx)(s.span,{})})})]})}),(0,a.jsx)(s.span,{className:"mclose nulldelimiter"})]}),(0,a.jsx)(s.span,{className:"mspace",style:{marginRight:"0.2778em"}}),(0,a.jsx)(s.span,{className:"mrel",children:"="}),(0,a.jsx)(s.span,{className:"mspace",style:{marginRight:"0.2778em"}})]}),(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"1.3005em",verticalAlign:"-0.4033em"}}),(0,a.jsxs)(s.span,{className:"mord",children:[(0,a.jsx)(s.span,{className:"mopen nulldelimiter"}),(0,a.jsx)(s.span,{className:"mfrac",children:(0,a.jsxs)(s.span,{className:"vlist-t vlist-t2",children:[(0,a.jsxs)(s.span,{className:"vlist-r",children:[(0,a.jsxs)(s.span,{className:"vlist",style:{height:"0.8972em"},children:[(0,a.jsxs)(s.span,{style:{top:"-2.655em"},children:[(0,a.jsx)(s.span,{className:"pstrut",style:{height:"3em"}}),(0,a.jsx)(s.span,{className:"sizing reset-size6 size3 mtight",children:(0,a.jsxs)(s.span,{className:"mord mtight",children:[(0,a.jsx)(s.span,{className:"mord mathnormal mtight",children:"m"}),(0,a.jsx)(s.span,{className:"mbin mtight",children:"+"}),(0,a.jsx)(s.span,{className:"mord mathnormal mtight",children:"i"}),(0,a.jsx)(s.span,{className:"mbin mtight",children:"\u22C5"}),(0,a.jsx)(s.span,{className:"mord mathnormal mtight",children:"d"})]})})]}),(0,a.jsxs)(s.span,{style:{top:"-3.23em"},children:[(0,a.jsx)(s.span,{className:"pstrut",style:{height:"3em"}}),(0,a.jsx)(s.span,{className:"frac-line",style:{borderBottomWidth:"0.04em"}})]}),(0,a.jsxs)(s.span,{style:{top:"-3.4461em"},children:[(0,a.jsx)(s.span,{className:"pstrut",style:{height:"3em"}}),(0,a.jsx)(s.span,{className:"sizing reset-size6 size3 mtight",children:(0,a.jsxs)(s.span,{className:"mord mtight",children:[(0,a.jsx)(s.span,{className:"mord mtight",children:"1000"}),(0,a.jsx)(s.span,{className:"mord mathnormal mtight",children:"p"})]})})]})]}),(0,a.jsx)(s.span,{className:"vlist-s",children:"\u200B"})]}),(0,a.jsx)(s.span,{className:"vlist-r",children:(0,a.jsx)(s.span,{className:"vlist",style:{height:"0.4033em"},children:(0,a.jsx)(s.span,{})})})]})}),(0,a.jsx)(s.span,{className:"mclose nulldelimiter"})]})]})]})]})}),"\n",(0,a.jsxs)(s.p,{children:["Crazy, right? The score is simply the (normalized) profit you made divided by the leverage plus days invested. The ",(0,a.jsxs)(s.span,{className:"katex",children:[(0,a.jsx)(s.span,{className:"katex-mathml",children:(0,a.jsx)(s.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,a.jsxs)(s.semantics,{children:[(0,a.jsxs)(s.mrow,{children:[(0,a.jsx)(s.mo,{children:"\u22C5"}),(0,a.jsx)(s.mn,{children:"1000"})]}),(0,a.jsx)(s.annotation,{encoding:"application/x-tex",children:"\\cdot 1000"})]})})}),(0,a.jsx)(s.span,{className:"katex-html","aria-hidden":"true",children:(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"0.6444em"}}),(0,a.jsx)(s.span,{className:"mord",children:"\u22C5"}),(0,a.jsx)(s.span,{className:"mord",children:"1000"})]})})]})," is just to turn the number into something more reasonable - people don't like hearing something with a profitability score of .001 for example."]}),"\n",(0,a.jsx)(s.h2,{id:"theoretical-justification",children:"Theoretical Justification"}),"\n",(0,a.jsx)(s.p,{children:"The formula itself is designed to be simple in principle: I like making a profit, and I want to penalize the leverage you incur and days you have to invest. Ideally, we want to have a stock that goes up all the time. However, the investment formula takes advantage of a different case: trying to profit from highly volatile assets. If we can make money when the investment only has one day up, let's do it!"}),"\n",(0,a.jsxs)(s.p,{children:["Even so, there are two potential issues: First, stocks that trend upward will have a higher profitability score - both leverage and days invested will be 1. To protect against only investing in this trend, I can do things like taking ",(0,a.jsxs)(s.span,{className:"katex",children:[(0,a.jsx)(s.span,{className:"katex-mathml",children:(0,a.jsx)(s.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,a.jsxs)(s.semantics,{children:[(0,a.jsxs)(s.mrow,{children:[(0,a.jsx)(s.mi,{children:"log"}),(0,a.jsx)(s.mo,{children:"\u2061"}),(0,a.jsx)(s.mo,{stretchy:"false",children:"("}),(0,a.jsx)(s.mi,{children:"d"}),(0,a.jsx)(s.mo,{stretchy:"false",children:")"})]}),(0,a.jsx)(s.annotation,{encoding:"application/x-tex",children:"\\log(d)"})]})})}),(0,a.jsx)(s.span,{className:"katex-html","aria-hidden":"true",children:(0,a.jsxs)(s.span,{className:"base",children:[(0,a.jsx)(s.span,{className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,a.jsxs)(s.span,{className:"mop",children:["lo",(0,a.jsx)(s.span,{style:{marginRight:"0.01389em"},children:"g"})]}),(0,a.jsx)(s.span,{className:"mopen",children:"("}),(0,a.jsx)(s.span,{className:"mord mathnormal",children:"d"}),(0,a.jsx)(s.span,{className:"mclose",children:")"})]})})]}),". I don't want to start biasing the scoring function until I have a practical reason to do so, so right now I'll leave it standing."]}),"\n",(0,a.jsx)(s.p,{children:"The second issue is how to penalize leverage and days invested relative to each other. As it currently stands, a leverage of 6x with only 1 day invested is the same as leveraging 2x with 3 days invested. In the future, I'd again want to look at making the impact of days invested smaller - I can get over an extra 3 days in the market if it means that I don't have to incur a highly leveraged position."}),"\n",(0,a.jsx)(s.p,{children:"So there could be things about the scoring function we change in the future, but I want to run some actual tests before we start worrying about things like that!"}),"\n",(0,a.jsx)(s.h2,{id:"running-a-simulation",children:"Running a simulation"}),"\n",(0,a.jsxs)(s.p,{children:["This won't be an incredibly rigorous backtest, I just want to see some results from the work so far. Let's set up the simulation code again, and start looking into some random stocks. ",(0,a.jsx)(s.strong,{children:"If you've read the last blog post, you can skip over the code."})," The only difference is that it's been ported to python to make the data-wrangling easier. Julia doesn't yet support some of the multi-index things I'm trying to do."]}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-python",children:'import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom Quandl import get as qget\n%matplotlib inline\napi_key = \'\'\n\nprofitability = lambda p, i, m, d: 1000*p / (m + i*d)\n\ndef is_profitable(current_price, purchase_history, open_history):\n shares = (purchase_history / open_history).sum()\n return current_price * shares > sum(purchase_history)\n\ndef daily_investment(current_open, current_close, purchase_history, open_history):\n t1 = current_close / current_open - 1\n t2 = (purchase_history - purchase_history * current_close / open_history).sum()\n return t2 / t1\n\ndef simulate_day(open_vals, close_vals, init, expected, bias):\n invested = np.array([init])\n \n day = 1\n profitable = is_profitable(close_vals[day-1], invested, open_vals[0:len(invested)]) \\\n or is_profitable(open_vals[day], invested, open_vals[0:len(invested)])\n\n while not profitable:\n expected_close = open_vals[day] * expected\n todays_purchase = daily_investment(open_vals[day], expected_close, invested, open_vals[0:day])\n invested = np.append(invested, todays_purchase + bias)\n # expected_profit = expected_close * (invested / open_vals[0:len(invested)]).sum() - invested.sum()\n day += 1\n profitable = is_profitable(close_vals[day-1], invested, open_vals[0:len(invested)]) \\\n or is_profitable(open_vals[day], invested, open_vals[0:len(invested)])\n \n shares = (invested / open_vals[0:len(invested)]).sum()\n \n # Make sure we can\'t see into the future - we know either today\'s close or tomorrow\'s open\n # will be profitable, but we need to check which one.\n if is_profitable(close_vals[day-1], invested, open_vals[0:len(invested)]):\n ending_price = close_vals[day-1]\n else:\n ending_price = open_vals[day]\n \n profit = shares * ending_price - sum(invested)\n return invested, profit\n\ndef simulate_ts(name, start, end, initial, expected, bias):\n ticker_info = qget(name, trim_start=start, api_key=api_key)\n evaluation_times = ticker_info[:end].index\n \n # Handle Google vs. YFinance data\n if "Adjusted Close" in ticker_info.columns:\n close_column = "Adjusted Close"\n else:\n close_column = "Close"\n \n sim = {d: simulate_day(ticker_info[d:]["Open"], ticker_info[d:][close_column],\n 100, 1.02, 10) for d in evaluation_times}\n sim_series = pd.Series(sim)\n result = pd.DataFrame()\n result["profit"] = sim_series.apply(lambda x: x[1])\n result["max"] = sim_series.apply(lambda x: max(x[0]))\n result["days"] = sim_series.apply(lambda x: len(x[0]))\n result["score"] = sim_series.apply(lambda x: profitability(x[1], x[0][0], max(x[0]), len(x[0])))\n result["investments"] = sim_series.apply(lambda x: x[0])\n \n return result\n\ndef simulate_tickers(tickers):\n from datetime import datetime\n results = {}\n for ticker in tickers:\n start = datetime(2015, 1, 1)\n results_df = simulate_ts(ticker, start, datetime(2016, 1, 1), 100, 1.01, 10)\n results[ticker] = results_df\n \n return pd.concat(list(results.values()), keys=list(results.keys()), axis=1)\n'})}),"\n",(0,a.jsx)(s.h2,{id:"and-now-the-interesting-part",children:"And now the interesting part"}),"\n",(0,a.jsx)(s.p,{children:"Let's start looking into the data! FANG stocks have been big over the past year, let's see how they look:"}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-python",children:'fang_df = simulate_tickers(["YAHOO/FB", "YAHOO/AAPL", "YAHOO/NFLX", "YAHOO/GOOG"])\n'})}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-python",children:"fang_df.xs('days', axis=1, level=1).hist()\nplt.gcf().set_size_inches(18, 8);\nplt.gcf().suptitle(\"Distribution of Days Until Profitability\", fontsize=18);\n"})}),"\n",(0,a.jsx)(s.p,{children:(0,a.jsx)(s.img,{alt:"png",src:t(58222).Z+"",width:"1048",height:"520"})}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-python",children:"fang_df.xs('score', axis=1, level=1).plot()\nplt.gcf().set_size_inches(18, 6)\nplt.gcf().suptitle(\"Profitability score over time\", fontsize=18);\n"})}),"\n",(0,a.jsx)(s.p,{children:(0,a.jsx)(s.img,{alt:"png",src:t(1122).Z+"",width:"1041",height:"388"})}),"\n",(0,a.jsx)(s.p,{children:"Let's think about these graphs. First, the histogram. What we like seeing is a lot of 1's - that means there were a lot of days that the stock went up and we didn't have to worry about actually implementing the strategy - we were able to close the trade at a profit."}),"\n",(0,a.jsx)(s.p,{children:"Looking at the profitability score over time though is a bit more interesting. First off, stocks that are more volatile will tend to have a higher profitability score, no two ways about that. However, Netflix consistently outperformed on this metric. We know that 2015 was a good year for Netflix, so that's a (small) sign the strategy is performing as expected."}),"\n",(0,a.jsx)(s.p,{children:"The final interesting note happens around the end of August 2015. Around this period, the markets were selling off in a big way due to issues in China (not unlike what's happening now). Even so, all of the FANG stocks saw an uptick in profitability around this time. This is another sign that the strategy being developed performs better during periods of volatility, rather than from riding markets up or down."}),"\n",(0,a.jsx)(s.p,{children:"What about FANG vs. some cyclicals?"}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-python",children:'cyclic_df = simulate_tickers(["YAHOO/X", "YAHOO/CAT", "YAHOO/NFLX", "YAHOO/GOOG"])\n'})}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-python",children:"cyclic_df.xs('days', axis=1, level=1).hist()\nplt.gcf().set_size_inches(18, 8);\nplt.gcf().suptitle(\"Distribution of Days Until Profitability\", fontsize=18);\n"})}),"\n",(0,a.jsx)(s.p,{children:(0,a.jsx)(s.img,{alt:"png",src:t(76991).Z+"",width:"1048",height:"520"})}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-python",children:"cyclic_df.xs('score', axis=1, level=1).plot()\nplt.gcf().set_size_inches(18, 6)\nplt.gcf().suptitle(\"Profitability score over time\", fontsize=18);\n"})}),"\n",(0,a.jsx)(s.p,{children:(0,a.jsx)(s.img,{alt:"png",src:t(60598).Z+"",width:"1041",height:"388"})}),"\n",(0,a.jsx)(s.p,{children:"Some more interesting results come from this as well. First off, US Steel (X) has a much smoother distribution of days until profitability - it doesn't have a huge number of values at 1 and then drop off. Intuitively, we're not terribly large fans of this, we want a stock to go up! However, on the profitability score it is the only serious contender to Netflix."}),"\n",(0,a.jsx)(s.p,{children:"Second, we see the same trend around August - the algorithm performs well in volatile markets."}),"\n",(0,a.jsx)(s.p,{children:"For a final test, let's try some biotech and ETFs!"}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-python",children:"biotech_df = simulate_tickers(['YAHOO/REGN', 'YAHOO/CELG', 'GOOG/NASDAQ_BIB', 'GOOG/NASDAQ_IBB'])\n"})}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-python",children:"biotech_df.xs('days', axis=1, level=1).hist()\nplt.gcf().set_size_inches(18, 8);\nplt.gcf().suptitle(\"Distribution of Days Until Profitability\", fontsize=18);\n"})}),"\n",(0,a.jsx)(s.p,{children:(0,a.jsx)(s.img,{alt:"png",src:t(17742).Z+"",width:"1048",height:"520"})}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-python",children:"biotech_df.xs('score', axis=1, level=1).plot()\nplt.gcf().set_size_inches(18, 6)\nplt.gcf().suptitle(\"Profitability score over time\", fontsize=18);\n"})}),"\n",(0,a.jsx)(s.p,{children:(0,a.jsx)(s.img,{alt:"png",src:t(37168).Z+"",width:"1041",height:"388"})}),"\n",(0,a.jsx)(s.p,{children:"In this example, we don't see a whole lot of interesting things: the scores are all fairly close together with notable exceptions in late August, and mid-October."}),"\n",(0,a.jsx)(s.p,{children:"What is interesting is that during the volatile period, the ETF's performed significantly better than the stocks did in terms of profitability. The leveraged ETF (BIB) performed far above anyone else, and it appears that indeed, it is most profitable during volatile periods. Even so, it was far more likely to take multiple days to give a return. Its count of 1-day investments trails the other ETF and both stocks by a decent margin."}),"\n",(0,a.jsx)(s.p,{children:"And consider me an OCD freak, but I just really like Celgene's distribution - it looks nice and smooth."}),"\n",(0,a.jsx)(s.h2,{id:"summary-and-plans-for-the-next-post",children:"Summary and plans for the next post"}),"\n",(0,a.jsx)(s.p,{children:"So far I'm really enjoying playing with this strategy - there's a lot of depth here to understand, though the preliminary results seem to indicate that it profits mostly from taking the other side of a volatile trade. I'd be interested to run results later on data from January - It's been a particularly volatile start to the year so it would be neat to see whether this strategy would work then."}),"\n",(0,a.jsx)(s.p,{children:"For the next post, I want to start playing with some of the parameters: How do the bias and expected close influence the process? The values have been fairly conservative so far, it will be interesting to see how the simulations respond afterward."})]})}function m(e={}){let{wrapper:s}={...(0,i.a)(),...e.components};return s?(0,a.jsx)(s,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},17742:function(e,s,t){t.d(s,{Z:function(){return n}});let n=t.p+"assets/images/_notebook_12_0-78c0e39ab1b402672551d197e388d2ba.png"},37168:function(e,s,t){t.d(s,{Z:function(){return n}});let n=t.p+"assets/images/_notebook_13_0-d109b38c5db52ca12be209a2a268c6eb.png"},58222:function(e,s,t){t.d(s,{Z:function(){return n}});let n=t.p+"assets/images/_notebook_4_0-46068cab7ea025b2c7ee79ad91eaf317.png"},1122:function(e,s,t){t.d(s,{Z:function(){return n}});let n=t.p+"assets/images/_notebook_5_0-85416fdde3eb77aa133be1e7dab17d9f.png"},76991:function(e,s,t){t.d(s,{Z:function(){return n}});let n=t.p+"assets/images/_notebook_8_0-f511f25f81b5b7b1baeaef267dd1a2b4.png"},60598:function(e,s,t){t.d(s,{Z:function(){return n}});let n=t.p+"assets/images/_notebook_9_0-1bd353a1fa4f84f07d0964b59b00be1e.png"},50065:function(e,s,t){t.d(s,{Z:function(){return r},a:function(){return l}});var n=t(67294);let a={},i=n.createContext(a);function l(e){let s=n.useContext(i);return n.useMemo(function(){return"function"==typeof e?e(s):{...s,...e}},[s,e])}function r(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),n.createElement(i.Provider,{value:s},e.children)}},93071:function(e){e.exports=JSON.parse('{"permalink":"/2016/02/profitability-using-the-investment-formula","source":"@site/blog/2016-02-26-profitability-using-the-investment-formula/index.mdx","title":"Profitability using the investment formula","description":"After developing a formula to guide our investing, how do we actually evaluate its performance in the real world?","date":"2016-02-26T12:00:00.000Z","tags":[],"readingTime":7.675,"hasTruncateMarker":true,"authors":[{"name":"Bradlee Speice","socials":{"github":"https://github.com/bspeice"},"key":"bspeice","page":null}],"frontMatter":{"slug":"2016/02/profitability-using-the-investment-formula","title":"Profitability using the investment formula","date":"2016-02-26T12:00:00.000Z","authors":["bspeice"],"tags":[]},"unlisted":false,"lastUpdatedAt":1730678252000,"prevItem":{"title":"Predicting Santander customer happiness","permalink":"/2016/03/predicting-santander-customer-happiness"},"nextItem":{"title":"Guaranteed money maker","permalink":"/2016/02/guaranteed-money-maker"}}')}}]); |