This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def formatter(str="{:0.2f}"): | |
return lambda x: str.format(x) | |
def to_latex(frame, filename, na_rep="", float_format=lambda number: "{:0.2f}".format(number)): | |
with open(filename, "w") as file: | |
frame.to_latex(buf=file, na_rep=na_rep, float_format=float_format, escape=False) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm -rf pybank | |
# clone the entire github repository. This is kind of inefficient as we delete the .git folder in a moment | |
git clone [email protected]:lobnek/pybank.git | |
cd pybank | |
VERSION=$1 | |
if [ "$VERSION" == "" ] | |
then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def monthlytable(nav, year=1900): | |
r = nav.pct_change().dropna() | |
# Works better in the first month | |
# Compute all the intramonth-returns, instead of reapplying some monthly resampling of the NAV | |
return_monthly = r.groupby([lambda x: x.year, lambda x: x.month]).apply(lambda x: (1 + x).prod() - 1.0) | |
frame = return_monthly.unstack(level=1).rename(columns=lambda x: calendar.month_abbr[x]) | |
a = (frame + 1.0).prod(axis=1) - 1.0 | |
frame["STDev"] = np.sqrt(12) * frame.std(axis=1) | |
# make sure that you don't include the column for the STDev in your computation | |
frame["YTD"] = a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import logging | |
class MailHandler(logging.Handler): | |
def emit(self, record): | |
send_message(subject=self.__subject, text=record, toAdr=self.__toAdr, fromAdr=self.__fromAdr, | |
mailgun=self.__mailgun, mailgunkey=self.__mailgunkey) | |
def __init__(self, level, format, subject, toAdr, fromAdr, mailgun, mailgunkey): | |
super().__init__() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
def drawdown(price): | |
high_water_mark = np.empty(len(price.index)) | |
moving_max_value = 0 | |
for i, value in enumerate(price.values): | |
moving_max_value = max(moving_max_value, value) | |
high_water_mark[i] = moving_max_value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import pandas as pd | |
class Engine(object): | |
def __init__(self, engine): | |
self.__engine = engine | |
def read(self, table, index_col): | |
logging.info('SELECT * FROM {0}'.format(table)) |
NewerOlder