Beispiel #1
0
def run_annual_pbr_per_combo(year, month=6, portfolio_num=30):
    # 거래일
    business_day = stock.get_business_days(year, month)
    start = business_day[0]
    business_day = stock.get_business_days(year + 1, month - 1)
    end = business_day[-1]

    # 2.5 <= PER  <= 10
    df = stock.get_market_fundamental_by_ticker(date=start, market="KOSPI")
    cond = (df["PER"] >= 2.5) & (df["PER"] <= 10)  # 괄호 주의
    df = df[cond]

    # PBR이 낮은 30 종목
    low_per = df["PBR"].nsmallest(n=portfolio_num)

    # 등락률
    fluctuation = stock.get_market_price_change_by_ticker(start, end)
    df = fluctuation.loc[low_per.index]

    # 수익률
    ror = 1 + (df['등락률'].mean() * 0.01)
    return ror
Beispiel #2
0
def marketStartEndTime():
    now = datetime.now()
    # now = datetime.date(datetime.utcnow() + relativedelta(months=1))
    print(now)
    print(now.year)
    print(now.month)
    days = stock.get_business_days(now.year, now.month)
    print(days)
    day = None
    for d in days:
        if (d > now):
            day = d
            break
    print(day)
    return days
Beispiel #3
0
def run_monthly_low_per(year, month, portfolio_num=5):
    # 거래일
    business_day = stock.get_business_days(year, month)
    start = business_day[0]
    end = business_day[-1]

    # PER 0인 종목 필터링
    df = stock.get_market_fundamental_by_ticker(date=start, market="KOSPI")
    cond = df["PER"] != 0
    df = df[cond]

    # PER이 낮은 n개 종목 선정
    low_per = df["PER"].nsmallest(n=portfolio_num)

    # 등락률
    fluctuation = stock.get_market_price_change_by_ticker(start, end)
    df = fluctuation.loc[low_per.index]

    # 수익률
    ror = 1 + (df['등락률'].mean() * 0.01)
    return ror
Beispiel #4
0
    })
    df = df.set_index('티커')
    소형주 = df.index.isin(tickers)
    PER_N0 = df['PER'] != 0
    정렬 = df[소형주 & PER_N0].sort_values(["PER"])
    투자종목 = 정렬.iloc[:투자종목수]
    return 투자종목.index.tolist()


#tickers = stock.get_index_portfolio_deposit_file("20181228", "의료정밀")

누적투자월 = 0
누적수익률 = 1
for year in range(2000, 2019):
    for month in range(1, 13):
        business_days = stock.get_business_days(year, month)
        tickers = stock.get_index_portfolio_deposit_file(
            business_days[0], "의료정밀")
        if tickers is None or len(tickers) == 0:
            print(business_days[0], "인덱스 X")
            continue

        name = "{}{:02d}".format(year, month)
        종목 = 종목선정("data/PERPBR_{}.xlsx".format(name), 20, tickers)
        수익률 = 월간수익률("data/PRICEC_{}.xlsx".format(name), 종목)
        누적수익률 *= 수익률
        print(name, "투자 {}".format(len(종목)), "{:2.2f}".format(수익률), "/ 누적수익 :",
              "{:2.2f}".format(누적수익률))
        누적투자월 += 1
        time.sleep(1)
Beispiel #5
0
from pykrx import stock

business_day = stock.get_business_days(2010, 1)
print(business_day[0])
print(business_day[-1])