Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
| Download
Project: Group Phd
Views: 51
Kernel: Python 3 (Anaconda)
2+2
4
import numpy as np
%time np.random.rand(1000,1000).max()
CPU times: user 16 ms, sys: 4 ms, total: 20 ms Wall time: 52.2 ms
0.99999937576182962
100/(1+0.1)
90.9090909090909
import sys
sys.version
'2.7.13 (default, Jul 22 2017, 09:28:25) \n[GCC 5.4.0 20160609]'
help
Type help() for interactive help, or help(object) for help about object.
help()
Welcome to Python 2.7! This is the online help utility. If this is your first time using Python, you should definitely check out the tutorial on the Internet at http://docs.python.org/2.7/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, or topics, type "modules", "keywords", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose summaries contain a given word such as "spam", type "modules spam".
help>
modules
topics
assertion
pv
7//3
7/3
x="HELLO"
y=x.strip()
k=y.strip()
print k
print k.strip()
def pv_f(fv,r,n): return fv/(1+r)**n
pv=round((100,0.10,1),(4))
round(pv,(4))
print pv
pv_f(r=0.10,fv=100,n=1)
dir()
import math
math.ceil(3.5)
math.ceil(1.13)
from math import *
sqrt(3.5)
pv_f(100,0.1,2)
def pv_perpetuity(c,r): # present value of perpetuity return c/r
pv_perpetuity(100,0.10)
# this is comment
help (pv_perpetuity)

#First Section

## Introduction
def pv_growing_perpetuity(c,r,g): if (r>g): print("r<g!!!!") else: return (c/(r-g))
pv_growing_perpetuity(10,0.10,0.08)
dir()
def npv_f(rate, cashflows): total = 0.0 for i, cashflow in enumerate(cashflows): total += cashflow / (1+rate)**i print total
r=0.05
cashflows=[-100,20,40,50,20,10]
npv_f=(r,[-100,20,40,50,20,10])
print npv_f
enumerate(cashflows)
cashflows[1]
dir()
record = [21,'bea','paris'] # lists can be modified
len(record)
record[0:]
record[1:]
def npv_f(rate,cashflows): total = 0.0 for i, cashflow in enumerate(cashflow): total += cashflow/(1+rate)**i print total
help(enumerate)
r=0.05
cashflows=[-100,20,40,50,20,10]
npv_f(r,cashflows)
dir()
def npv_f(r,cashflows): total = 0.0 for i, cashflow in enumerate(cashflow): total += cashflow/(1+r)**i print total
r=0.05
cashflows=[-100,20,40,50,20,10]
print npv_f
npv_f(r,cashflows)
npv_f = cashflows/(1+r)**i
print total
def npv_f (rate,cashflows): total = 0.0 for i, cashflow in enumerate (cashflows): total += cashflow / (1+rate)**i print total
r=0.05
cashflows = [-100,20,40,50,20,10]
npv_f(r,cashflows)
dir()
def IRR_f (cashflows,interations=100): rate=1.0 investment=cashflows[0] for i in range (1,interations+1): rate*= (1-npv_f(rate, cashflows)/investment) print rate
cashflows = [-100,20,40,50,20,10]
npv_f(1,cashflows)
dir()
dir()
npv_f(2,cashflows)
x y 1 2 3 4 5 6
import pandas as pd
data=pd.read_clipboard()
data
x y 1 2 3 4 5 6
import pandas as pd
data=pd.read_clipboard()
data
from matplotlib.finance import quotes_historical_yahoo
import pandas as pd
data=pd.read_clipboard()
import win32clipboard
from matplotlib.finance import quotes_historical_yahoo
x y 1 2 3 4 5 6
import pandas as pd
x=10
print x
import numpy as np
import pandas as pd
dates=pd.date_range('20130101', periods=5)
np.random.seed(12345)
x=pd.DataFrame(np.random.rand(5,2),index=dates,columns=('A','B'))
x
x.describe
x.describe()
import numpy as np
import pandas as pd
x=pd.date_range('1/1/2013', periods=252)
data = pd.Series(np.random.randn(len(x)),index=x)
data.head()
data.tail
def payoff_call(sT,x): return (sT-x + abs(sT-x))/2
print payoff_call(25,30)
print payoff_call(40,30)
import numpy as np
x=20
sT=np.arange(10,50,10)
sT
payoff_call(sT,x)
import numpy as np
np.arange(3,7)
np.arange(10,60,5)
sT=np.arange(10,50,10)
payoff_call(sT,x)
def payoff_call(sT,x): return (sT-x + abs(sT-x))/2
ylim(-10,50)
sT=np.arange(10,50,10)
sT
x=20
print payoff_call
payoff_call(sT,x)
import numpy as np
s=np.arange(10,80,5)
x=30
payoff=(abs(s-x)+s-x)/2
ylim(-10,50)
plot(s,payoff)
import numpy as np
import pandas as pd
dates=pd.date_range('20130101',periods=5)
np.random.seed(12345)
x=pd.DataFrame(np.random.rand(5,2),index=dates,columns=('A','B'))
x
x.describe
import pandas as pd
import numpy as np
x=pd.Series([0.1,0.002,-0.03,np.nan,0.13,0.125])
x
m=np.mean(x)
round(m,4)
y=x.fillna(m)
y
import numpy as np
import statsmodels.api as sm
y=[1,2,3,4,2,3,4]
x=range(1,8)
x=sm.add_constant(x)
results=sm.OLS(y,x).fit()
print results.params
import pandas as pd
import numpy as np
p=np.array([1,1.1,0.9,1.05])
print(p[:-1])
[ 1. 1.1 0.9]
print(p[1:])
[ 1.1 0.9 1.05]
ret=(p[1:]-p[:-1])/p[:-1]
print ret
[ 0.1 -0.18181818 0.16666667]
import matplotlib.pyplot as plt import pandas as pd
data_source='yahoo'
tickers = ['AAPL', 'MSFT', 'GSPC']
start_date='2015-12-01'
end_date='2016-12-01'
import pandas as pd
import pandas_datareader as pdr
import datetime
start = datetime.datetime(2015,12,1)
end = datetime.datetime(2016,12,1)
import pandas_datareader
import pandas_datareader.data as web
import datetime
start = datetime.datetime(2015,12,1)
end = datetime.datetime(2016,12,1)
from pandas_datareader.data import Options
aapl = Options('aapl', 'yahoo')
data = aapl.get_all_data()
WARNING: Some output was deleted.
data.iloc[0:5, 0:5]
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-22-6912f393f50f> in <module>() ----> 1 data.iloc[0:5, 0:5] NameError: name 'data' is not defined
import numpy as np
import pandas as pd
ticker='IBM'
begdate=(2005,1,1)
enddate=(2010,1,1)
fh = fetch_historical_yahoo('^IBM', (2000, 1, 1), (2001, 12, 31))
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-16-670a37b6d762> in <module>() ----> 1 fh = fetch_historical_yahoo('^IBM', (2000, 1, 1), (2001, 12, 31)) NameError: name 'fetch_historical_yahoo' is not defined