<jupyter_start><jupyter_text><jupyter_code>import io
import os
import pandas as pd
import numpy as np
from google.colab import drive
drive.mount('/gdrive')
name = 'AMD_option_sigma'
option = pd.read_csv('/gdrive/My Drive/Data set/Option/sigma_file/'+name+'.csv')
DSG_data = pd.read_csv('/gdrive/My Drive/Data set/Option/DGS/DSG_ALL.csv')
option
from datetime import datetime
def datetime_cal(date_str):
    return datetime.strptime(date_str,'%m/%d/%Y')

def datetime_diff(row):
  row['date_diff'] = row.apply(lambda _: '', axis=1)
  for i in range(len(row)):
    row['date_diff'][i] = (datetime_cal(row["Expiration"][i]) - datetime_cal(row["DataDate"][i].split(' ')[0])).days
datetime_diff(option)
diff_option = option
def datetime_cal2(date_str):
    return datetime.strptime(date_str,'%Y-%m-%d')
def add_treasury_rate(row):
  row['treasury_rate'] = row.apply(lambda _: '', axis=1)
  for i in range(len(row)):
    for k in range(len(DSG_data)):
      if datetime_cal(row["DataDate"][i].split(' ')[0]) == datetime_cal2(DSG_data["DATE"][k]):
        if row["date_diff"][i] <= 45:
            select = 'DGS1MO'
        elif row["date_diff"][i] <= 135:
            select = 'DGS3MO'
        elif row["date_diff"][i] <= 270:
            select = 'DGS6MO'
        elif row["date_diff"][i] <= 547:
            select = 'DGS1'
        elif row["date_diff"][i] <= 912:
            select = 'DGS2'
        else:
            select = 'DGS3'
        row['treasury_rate'][i] = DSG_data[select][k]
add_treasury_rate(diff_option)
diff_option.to_csv('/gdrive/My Drive/Data set/Option/Tresury_rate/'+name+'_TresuryRate.csv')
diff_option<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup