projects upcoming
play

Projects (upcoming) Assess Portfolio Machine Learning for Trading - PowerPoint PPT Presentation

Projects (upcoming) Assess Portfolio Machine Learning for Trading Assess Learners & Defeat Learners Software Platform Market Simulator Introduction & Installation Towards Sharpe Ratio Sharpe Ratio 1 Intuition Considers


  1. Projects (upcoming) • Assess Portfolio Machine Learning for Trading • Assess Learners & Defeat Learners Software Platform • Market Simulator Introduction & Installation Towards Sharpe Ratio Sharpe Ratio 1 Intuition • Considers our return in • Considers our return in the context of risk the context of risk 2 • Risk is volatile • Risk is volatile (standard deviation) (standard deviation) • Adjust our return in • Adjust our return in return for the risk return for the risk 3 • Volatility • Volatility – Measured by standard – Measured by standard deviation deviation

  2. Sharpe Ratio Sharpe Ratio 1 • Adjusts the 1. Higher Returns is Better – return for risk 2. Less Volatility/Less Risk • A quantitative way to assess a portfolio 2 – 1. ABC is better because it has the same volatility but higher is Better returns – 2. same returns but XYZ has lower risk so XYZ is better 3. Not Enough Information – 3. A quantity such as the Sharpe Ratio may give you a number to – Returns: ABC > XYZ determine which is better • Sharpe ratio also considers (comparative) 3 – Volatility ABC > XYZ – Risk free rate of returns – ABC is higher returns, • Example Bank account or treasure note – Lately risk free return is 0, bank interest rate is 0, or close to 0 but more risk – Caveat: When computing Sharpe Ratio need to be careful of the risk free returns rate: • Annual, weekly, daily Heuristics Sharpe Ratio Intuition: Which Formula is Best? Consider Parameters to include in formula: • R p : Portfolio Return • Sharpe Ratio Answers: Is the • R f : Risk Free Rate of Return portfolio return due to intelligent investment decisions or the result • σ p : Standard Deviation of Portfolio Return of excessive risk taken by the investor? • The greater a portfolio’s Sharpe a) R p – R f + σ p ratio: b) R f / R f - σ p • The better its risk-adjusted performance has been. c) (R p – R f) / σ p • A negative Sharpe ratio indicates that a risk-less asset (risk free) would perform better than the portfolio (return) being analyzed.” General Form of the Sharpe Ratio

  3. Computing Sharpe Ratio Risk Free Rate • If you have annual rate and want Effective • Expected return : Can use mean() of daily returns Daily Rate compounded daily. (accessible via yahoo finance). • Caveat: Compound interest is not linear with • StD() of daily returns. time. • StD() of the Return of the Risk Free Rate N th – Standard deviation of a constant is 0 (can remove). 1 + Annualized Re turn − 1 • What is the risk free rate ? Example: 2.5% Annual Return - Going to – LIBOR (London Inter Bank Offer Rate) effective daily return – 242 trading days in a – Interest Rate: 3 months Treasury Bill (Standard) year. – 0%! Short Cut. – If you use daily returns, then the risk free rate needs to be at 242 1 + 0.025 − 1 the same sampling rate: • So if you are referencing an annual rate then you will need to convert it to a daily risk free rate. =POWER(1+0.025,1/242)-1 Computing SR Summary • Sharpe Ratio itself is an annual measure , so if • 2 things to consider when computing Sharpe we are sampling at a different rate e.g. daily, Ratio: need an adjustment factor to convert it to the – 1) Convert Risk Free Rate to same period as correct period expected return period. Sample Rate K (convert to annual) Daily � � � – 2) Convert SR to annual SR. (using adjustment – SR annualized = k * SR Weekly �� � factor k). Monthly �� � SR = � � �

  4. Quiz: What is the Sharpe Ratio? Quiz: What is the Sharpe Ratio? • 60 Days of Data • 60 Days of Data • BPS – Basis points are tenths of percentages. • BPS – Basis points are tenths of percentages. • Average Daily Return = 10 bps = 0.001 • Average Daily Return = 10 bps = 0.001 • Daily Risk Free Rate = 2 bps = 0.0002 • Daily Risk Free Rate = 2 bps = 0.0002 • Standard Deviation Daily Return = 10 bps = 0.001 • Standard Deviation Daily Return = 10 bps = 0.001 SR = SQRT ( Period ) * mean (R portfolio - R RiskFree ) SR = SQRT ( Period ) * mean (R portfolio - R RiskFree ) -------------------------------- -------------------------------- Std( Daily Return) Std( Daily Return) SR = SQRT ( Period ) * (10-2) SR = SQRT ( Period ) * (10-2) ------- ------- 10 10 Project Demo Get the Daily Total Value of the Portfolio • Step 1 : Prices Data Frame index by dates Given: Given: – prices is a frame. start_val = $1,000,000 start_val = $1,000,000 • Step 2 : Normalize by First Row start_date = 2011-01-01 start_date = 2011-01-01 – normed = prices/prices[0] end_date = 2011-12-31 end_date = 2011-12-31 • Step 3 : Multiply by allocation (a vector) symbols =[‘SPY’,’XOM’, symbols =[‘SPY’,’XOM’, ’GOOG’, ‘GLD’] ’GOOG’, ‘GLD’] – allocated = normed * allocs allocs = [0.4,0.4,0.1,0.1] allocs = [0.4,0.4,0.1,0.1] • Step 4 : Position values = worth each day – pos_vals = allocated * start_val • Step 5 : Daily Total Value of Portfolio – port_vals = pos_vals.sum(axis = 1) pos_vals.sum( axis = 1 ) prices/prices[0] allocated * start_val normed/allocs • Compute port_val and statistics … prices normed allocated pos_vals port_vals port_vals = get_portfolio_value( prices, allocs, start_val)

  5. Optimization Compute Statistics • Average Daily Return Given: Given: 1) port_vals 1) port_vals: portfolio : portfolio – Intuition : • What is an optimizer? daily return values daily return values • Today/Yesterday - 1 2) 2) rfr rfr: risk free rate : risk free rate 1. Find minimum values of functions 3) sample_frequency: Sample : Sample • Remove 1 st row since now it is all 0s Frequency Frequency – Example, Example, – Excel a cell G10 = E10/E9-1 • Example: f(x) = x 2 + x 3 + … + 1 daily 252 in a year. daily 252 in a year. • E10 = current’s row adjusted close 2. Find parameters from data • E09 = previous day’s adjusted close – Pandas: • Enables: building parameterized models based on data • daily_rets = port_val / port_val.shift(X) - 1 • How: polynomial fit to data • # what is X? • Cumulative from beginning to end 3. Find (refine) allocation of stocks in a portfolio – >= period than daily return. • What percentage should be allocated to each stock to • Average and Standard Deviation of the maximize the portfolio return (part of the project). Daily Return .mean(), .std() • Sharpe Ratio (Annual) cr, adr, sddr, sr = get_portfolio_stats( port_val, risk_free_rate, sample_frequency) Find Minima of a Function Example: Minimization 1) Function provided: • How to use an optimizer: http://www.wolframalpha.com/ – f(x) = (x – 1.5) 2 + 0.5 min( x- 1.5)^2 + 0.5 ) 1) Provide a function to minimize: 2) Provide an initial guess: 3.0 Example: f(x) = x 2 + 0.5 • 3) Call Optimizer with parameters 2) Provide an initial guess: defined above. Example = 5 (generated by a randomizer) • – One method: Gradient descend to narrow in on 3) Call the optimizer with the parameters above • the solution. • Experiment with other methods. • Next: Look at Code (provided): – pdf-code-finance/001-minimizer.py f(x) : Y = ( X - 1 . 5 ) **2 + 0 . 5 # parabola at X = 1 . 5 Y = 0 . 5 min_result = spo.minimize( f , Xguess, method='SLSQP', options = {'disp':True})

  6. Exercise: Minimization Exercise: Minimization 1) Function provided: 1) Function provided: – f(x) = (x 1 ) 2 + (x 2 ) 2 – f(x) = (x 1 ) 2 + (x 2 ) 2 http://www.wolframalpha.com/ http://www.wolframalpha.com/ min( X1 ^ 2 + X2 ^ 2 ) min( X1 ^ 2 + X2 ^ 2 ) 2) Provide an initial guess: [1,1] 2) Provide an initial guess: [1,1] 3) Call Optimizer with parameters 3) Call Optimizer with parameters defined above. defined above. – One method: – One method: Gradient descend to narrow in on Gradient descend to narrow in on • • the solution. the solution. Experiment with other methods. Experiment with other methods. • • • Code Snippets: • Code Snippets: x1, x2 = params optimize1D2.py x1, x2 = params optimize1D2.py Z = x1**2 + x2**2 Z = x1**2 + x2**2 Xguess = [1,1] Xguess = [1,1] min_result = spo.minimize( f , Xguess, method='SLSQP', options = {'disp':True}) min_result = spo.minimize( f , Xguess, method='SLSQP', options = {'disp':True}) Which functions are challenging to Exercise solve (for the minimizer)? #min ( X1 + 0 . 5 )^ 2 + • A ( X2 - 0 . 25 ) ^ 2 + sin ( 3X1 ) + sin ( 5X2 ) • B • C • D

  7. Which functions are challenging to solve (for the minimizer)? • Convex functions are guaranteed to find a • A – flat areas don’t have a gradient. minima (only one). • But – other algorithms for specific issues, you • B - convex problems can experiment with different ones on your own. • C – several global minima • D – discontinuity (and a flat area). Convex Problems Parameterized models from data • Example: f(x) = mx + b – c 1 x + c 0 – c 3 x 3 + c 2 x 2 + c 1 x + c 0 • Goal 1 : Find parameters of the • Convex function line c 0 , c 1 , where c 0 is the y- intercept, and c 1 is slope that • Wikipedia : "... a real-valued function f(x) best fits the data • Goal 2 : How do we reframe the defined on an interval is called convex if the rain problem so that it makes sense line segment between any two points on the to the minimizer? • What should we be graph of the function lies above the graph ..." minimizing? humidity 003-parameters-data.py

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend