Skip to content

Commit

Permalink
Updated examples/*.py
Browse files Browse the repository at this point in the history
  • Loading branch information
christianjauregui committed May 2, 2020
1 parent 167dd67 commit 3681dbc
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 147 deletions.
14 changes: 8 additions & 6 deletions examples/famafrench_3factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/Data_Library/f-f_factors.html
"""

import os
import datetime as dt
import famafrench.famafrench as ff
from importlib import reload
import datetime as dt

# Example of how to re-load a distribution module/package
reload(ff)
Expand All @@ -35,14 +35,16 @@
ffFactors = ['MKT-RF', 'SMB', 'HML']
ffportCharac = ['ME', 'BM']

# pickled_dir
pickled_dir = os.getcwd() + 'famafrench/pickled_db/'

#%%
#********************************************************************************************#
# Example 1: daily sample
#********************************************************************************************#
runQuery = True
ffFreq = 'D'
ff_D = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_D = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# Summary statistics
ff_D.getFamaFrenchStats('Factors', ffFreq, startDate, endDate)
Expand All @@ -59,7 +61,7 @@
#********************************************************************************************#
runQuery = True
ffFreq = 'W'
ff_W = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_W = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# Summary statistics
ff_W.getFamaFrenchStats('Factors', ffFreq, startDate, endDate)
Expand All @@ -76,7 +78,7 @@
#********************************************************************************************#
runQuery = True
ffFreq = 'M'
ff_M = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_M = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# Summary statistics
ff_M.getFamaFrenchStats('Factors', ffFreq, startDate, endDate)
Expand All @@ -93,7 +95,7 @@
#********************************************************************************************#
runQuery = False
ffFreq = 'A'
ff_A = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_A = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# Summary statistics
ff_A.getFamaFrenchStats('Factors', ffFreq, startDate, endDate)
Expand Down
14 changes: 8 additions & 6 deletions examples/famafrench_5factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/Data_Library/f-f_5_factors_2x3.html
"""

import famafrench.famafrench as ff
import os
import datetime as dt
import famafrench.famafrench as ff

startDate = dt.date(1960, 1, 1) # "default" startDate
endDate = dt.date.today() # "default" endDate
Expand All @@ -33,14 +33,16 @@
ffFactors = ['MKT-RF', 'SMB', 'HML', 'RMW', 'CMA']
ffportCharac = ['ME', 'BM', 'OP', 'INV']

# pickled_dir
pickled_dir = os.getcwd() + 'famafrench/pickled_db/'

#%%
#********************************************************************************************#
# Example 1: daily sample
#********************************************************************************************#
runQuery = True
ffFreq = 'D'
ff_D = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_D = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# Summary statistics
ff_D.getFamaFrenchStats('Factors', ffFreq, startDate, endDate)
Expand All @@ -57,7 +59,7 @@
#********************************************************************************************#
runQuery = False
ffFreq = 'W'
ff_W = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_W = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# Summary statistics
portTableW = ff_W.getFFfactors(startDate, endDate)
Expand All @@ -70,7 +72,7 @@
#********************************************************************************************#
runQuery = True
ffFreq = 'M'
ff_M = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_M = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# Summary statistics
ff_M.getFamaFrenchStats('Factors', ffFreq, startDate, endDate)
Expand All @@ -87,7 +89,7 @@
#********************************************************************************************#
runQuery = False
ffFreq = 'A'
ff_A = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_A = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# Summary statistics
ff_A.getFamaFrenchStats('Factors', ffFreq, startDate, endDate)
Expand Down
18 changes: 10 additions & 8 deletions examples/famafrench_allsorts_me_ac.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@
https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/Data_Library/tw_5_ports_me_AC.html
"""

import famafrench.famafrench as ff
import os
import datetime as dt
import famafrench.famafrench as ff

startDate = dt.date(1960, 1, 1) # "default" startDate
endDate = dt.date.today() # "default" endDate
#startDate = dt.date(1970, 1, 1)
#endDate = dt.date(2019, 12, 31)

# pickled_dir
pickled_dir = os.getcwd() + 'famafrench/pickled_db/'

#%%
#**************************************************************************#
Expand All @@ -44,7 +46,7 @@
runQuery = True
ffFreq = 'D'
ffFactors, ffsortCharac, ffportCharac = [], ['AC'], ['AC']
ff_D = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_D = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 3 portfolios (3x1) sorted on ['AC']
sortingDim = [3]
Expand Down Expand Up @@ -72,7 +74,7 @@
runQuery = True
ffFreq = 'M'
ffFactors, ffsortCharac, ffportCharac = [], ['AC'], ['ME', 'AC']
ff_M = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_M = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 3 portfolios (3x1) sorted on ['AC']
sortingDim = [3]
Expand Down Expand Up @@ -108,7 +110,7 @@
runQuery = False
ffFreq = 'A'
ffFactors, ffsortCharac, ffportCharac = [], ['AC'], ['ME', 'AC']
ff_A = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_A = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 3 portfolios (3x1) sorted on ['AC']
sortingDim = [3]
Expand Down Expand Up @@ -146,7 +148,7 @@
runQuery = True
ffFreq = 'D'
ffFactors, ffsortCharac, ffportCharac = [], ['ME', 'AC'], ['ME', 'AC']
ff_D = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_D = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 6 portfolios (2x3) sorted on ['ME, 'AC']
sortingDim = [2, 3]
Expand Down Expand Up @@ -174,7 +176,7 @@
runQuery = True
ffFreq = 'M'
ffFactors, ffsortCharac, ffportCharac = [], ['ME', 'AC'], ['ME', 'AC']
ff_M = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_M = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 6 portfolios (2x3) sorted on ['ME, 'AC']
sortingDim = [2, 3]
Expand Down Expand Up @@ -207,7 +209,7 @@
runQuery = False
ffFreq = 'A'
ffFactors, ffsortCharac, ffportCharac = [], ['ME', 'AC'], ['ME', 'AC']
ff_A = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_A = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 6 portfolios (2x3) sorted on ['ME, 'AC']
sortingDim = [2, 3]
Expand Down
20 changes: 11 additions & 9 deletions examples/famafrench_allsorts_me_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/Data_Library/tw_5_ports_me_BETA.html
"""

import famafrench.famafrench as ff
import os
import datetime as dt
import famafrench.famafrench as ff

startDate = dt.date(1960, 1, 1) # "default" startDate
endDate = dt.date.today() # "default" endDate
#startDate = dt.date(1970, 1, 1)
#endDate = dt.date(2019, 12, 31)

# pickled_dir
pickled_dir = os.getcwd() + 'famafrench/pickled_db/'


#%%
#***************************************************************************#
#***************************************************************************#
#***************** Market Beta (BETA) *******************#
Expand All @@ -44,7 +46,7 @@
runQuery, runEstimation = False, True
ffFreq = 'D'
ffFactors, ffsortCharac, ffportCharac = [], ['BETA'], ['BETA']
ff_D = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)
ff_D = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)

# - 3 portfolios (3x1) sorted on ['BETA']
sortingDim = [3]
Expand Down Expand Up @@ -72,7 +74,7 @@
runQuery, runEstimation = False, True
ffFreq = 'M'
ffFactors, ffsortCharac, ffportCharac = [], ['BETA'], ['ME', 'BETA']
ff_M = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)
ff_M = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)

# - 3 portfolios (3x1) sorted on ['BETA']
sortingDim = [3]
Expand Down Expand Up @@ -107,7 +109,7 @@
runQuery, runEstimation = False, True
ffFreq = 'A'
ffFactors, ffsortCharac, ffportCharac = [], ['BETA'], ['ME', 'BETA']
ff_A = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)
ff_A = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)

# - 3 portfolios (3x1) sorted on ['BETA']
sortingDim = [3]
Expand Down Expand Up @@ -145,7 +147,7 @@
runQuery, runEstimation = False, True
ffFreq = 'D'
ffFactors, ffsortCharac, ffportCharac = [], ['ME', 'BETA'], ['ME', 'BETA']
ff_D = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)
ff_D = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)

# - 6 portfolios (2x3) sorted on ['ME, 'BETA']
sortingDim = [2, 3]
Expand Down Expand Up @@ -173,7 +175,7 @@
runQuery, runEstimation = False, True
ffFreq = 'M'
ffFactors, ffsortCharac, ffportCharac = [], ['ME', 'BETA'], ['ME', 'BETA']
ff_M = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)
ff_M = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)

# - 6 portfolios (2x3) sorted on ['ME, 'BETA']
sortingDim = [2, 3]
Expand Down Expand Up @@ -204,7 +206,7 @@
runQuery, runEstimation = False, True
ffFreq = 'A'
ffFactors, ffsortCharac, ffportCharac = [], ['ME', 'BETA'], ['ME', 'BETA']
ff_A = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)
ff_A = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac, runEstimation)

# - 6 portfolios (2x3) sorted on ['ME, 'BETA']
sortingDim = [2, 3]
Expand Down
18 changes: 10 additions & 8 deletions examples/famafrench_allsorts_me_ltrev.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@
https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/Data_Library/det_25_port_form_sz_pr_60_13_daily.html
"""

import famafrench.famafrench as ff
import os
import datetime as dt
import famafrench.famafrench as ff

startDate = dt.date(1960, 1, 1) # "default" startDate
endDate = dt.date.today() # "default" endDate
#startDate = dt.date(1970, 1, 1)
#endDate = dt.date(2019, 12, 31)

# pickled_dir
pickled_dir = os.getcwd() + 'famafrench/pickled_db/'

#%%
#*****************************************************************************#
Expand All @@ -51,7 +53,7 @@
runQuery = True
ffFreq = 'D'
ffFactors, ffsortCharac, ffportCharac = [], ['PRIOR_13_60'], ['ME', 'PRIOR_13_60']
ff_D = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_D = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 3 portfolios (3x1) sorted on ['PRIOR_13_60']
sortingDim = [3]
Expand Down Expand Up @@ -80,7 +82,7 @@
runQuery = True
ffFreq = 'M'
ffFactors, ffsortCharac, ffportCharac = [], ['PRIOR_13_60'], ['ME', 'PRIOR_13_60']
ff_M = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_M = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 3 portfolios (3x1) sorted on ['PRIOR_13_60']
sortingDim = [3]
Expand Down Expand Up @@ -113,7 +115,7 @@
runQuery = False
ffFreq = 'A'
ffFactors, ffsortCharac, ffportCharac = [], ['PRIOR_13_60'], ['ME', 'PRIOR_13_60']
ff_A = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_A = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 3 portfolios (3x1) sorted on ['PRIOR_13_60']
sortingDim = [3]
Expand Down Expand Up @@ -149,7 +151,7 @@
runQuery = True
ffFreq = 'D'
ffFactors, ffsortCharac, ffportCharac = [], ['ME', 'PRIOR_13_60'], ['ME', 'PRIOR_13_60']
ff_D = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_D = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 6 portfolios (2x3) sorted on ['ME, 'PRIOR_13_60']
sortingDim = [2, 3]
Expand Down Expand Up @@ -179,7 +181,7 @@
runQuery = True
ffFreq = 'M'
ffFactors, ffsortCharac, ffportCharac = [], ['ME', 'PRIOR_13_60'], ['ME', 'PRIOR_13_60']
ff_M = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_M = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 6 portfolios (2x3) sorted on ['ME, 'PRIOR_13_60']
sortingDim = [2, 3]
Expand Down Expand Up @@ -213,7 +215,7 @@
runQuery = False
ffFreq = 'A'
ffFactors, ffsortCharac, ffportCharac = [], ['ME', 'PRIOR_13_60'], ['ME', 'PRIOR_13_60']
ff_A = ff.FamaFrench(runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)
ff_A = ff.FamaFrench(pickled_dir, runQuery, ffFreq, ffsortCharac, ffFactors, ffportCharac)

# - 6 portfolios (2x3) sorted on ['ME, 'PRIOR_13_60']
sortingDim = [2, 3]
Expand Down

0 comments on commit 3681dbc

Please sign in to comment.