feat: add filter toggle button

This commit is contained in:
monoid 2023-07-24 09:10:32 +09:00
parent a6635ccee6
commit 9c88d4c246
7 changed files with 590 additions and 193 deletions

View File

@ -19,6 +19,8 @@
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.0",
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.2.3",
"auto-animate": "https://esm.sh/@formkit/auto-animate@0.7.0",
"auto-animate/": "https://esm.sh/@formkit/auto-animate@0.7.0/",
"twind": "https://esm.sh/twind@0.16.19",
"twind/": "https://esm.sh/twind@0.16.19/",
"$std/": "https://deno.land/std@0.193.0/"

8
gen.py
View File

@ -156,7 +156,7 @@ def collect(data: DataStore, collector: OutputCollector, corp: database.KRXCorp
bollinger_upperband = d25 + 2* d_std25
a = [d20, d30, d60, d120]
a = [d5, d20, d45, d60]
for nday in ndays:
if openv[nday] <= d20[nday] and d20[nday] <= close[nday]:
collector.collect("양봉사이20일선", corp, stock.index[nday])
@ -171,14 +171,14 @@ def collect(data: DataStore, collector: OutputCollector, corp: database.KRXCorp
if every(lambda i: isRelativeDiffLessThan(i,close,0.01,nday), a):
collector.collect("뭉침01", corp, stock.index[nday])
if d120[nday + 1] < d120[nday]:
collector.collect("뭉침1% 120선 상승", corp, stock.index[nday])
if every(lambda i: isRelativeDiffLessThan(i,close,0.03,nday), a):
collector.collect("뭉침03", corp, stock.index[nday])
if d120[nday + 1] < d120[nday]:
collector.collect("뭉침3% 120선 상승", corp, stock.index[nday])
if every(lambda i: isRelativeDiffLessThan(i,close,0.05,nday), [d20, d30, d60, d120, d240]):
collector.collect("뭉침 240선까지", corp, stock.index[nday])
if (d5[nday] > d20[nday] and d5[nday + 1] < d20[nday + 1]):
collector.collect("cross d20 and d5", corp, stock.index[nday])

View File

@ -1,20 +1,33 @@
import { Button } from "../components/Button.tsx";
import { useEffect } from "preact/hooks";
import { useEffect, useRef } from "preact/hooks";
import { ComponentChildren } from "preact";
import { Signal, useSignal } from "@preact/signals";
import { IS_BROWSER } from "$fresh/runtime.ts";
import { mapValues } from "$std/collections/map_values.ts";
interface StockProps {
pageName: string;
}
interface ToggleButtonProps {
disabled?: boolean;
toggle: Signal<boolean>;
children?: ComponentChildren;
}
function ToggleButton(props: ToggleButtonProps) {
const { disabled, toggle, ...rest } = props;
return (
<Button {...props}>
</Button>
<button
{...rest}
disabled={!IS_BROWSER || disabled}
onClick={() => toggle.value = !toggle.value}
class={"px-2 py-1 border-2 rounded transition-colors" + (
toggle.value
? "border-gray-500 bg-white hover:bg-gray-200"
: "border-gray-200 bg-gray-800 hover:bg-gray-500 text-white"
)}
/>
);
}
@ -28,36 +41,26 @@ type QueryStatus<T> = {
err: Error;
};
const cacheMap = new Map<string, unknown>();
function useQuery<T>(url: string): Signal<QueryStatus<T>> {
function useAsync<T>(fn: () => Promise<T>): Signal<QueryStatus<T>> {
const state = useSignal({
type: "loading",
} as QueryStatus<T>);
useEffect(() => {
if (!cacheMap.has(url)) {
(async () => {
try {
const res = await fetch(url);
const data = await res.json();
cacheMap.set(url, data);
state.value = {
type: "complete",
data: data,
};
} catch (err) {
state.value = {
type: "error",
err: err,
};
}
})();
} else {
state.value = {
type: "complete",
data: cacheMap.get(url) as T,
};
}
},[]);
(async () => {
try {
const data = await fn();
state.value = {
type: "complete",
data: data,
};
} catch (err) {
state.value = {
type: "error",
err: err,
};
}
})();
}, []);
return state;
}
@ -80,47 +83,153 @@ interface PageCorpsInfo {
corpListByDate: Record<string, Coperation[]>;
}
function StockList({data}: {data: PageCorpsInfo}){
console.log("data")
const keys = Object.keys(data.corpListByDate).sort().reverse().slice(0,5).reverse();
//const rows = data.corpListbyDate;
interface CorpSimple {
code: string;
name: string;
}
return <div class="flex">
{keys.map((x,i)=>{
const rows = data.corpListByDate[x];
return <div key={x}>
{rows.map(row=>{
return <div>
{row.Name}
</div>
})}
</div>
})}
function StockListByDate({prevSet, rows, name}:{prevSet:Set<string>,
rows:Coperation[],
name: string}){
const parent = useRef<HTMLDivElement>(null);
useEffect(()=>{
(async ()=>{
const {default:autoAnimate} = await import("https://esm.sh/@formkit/auto-animate@0.7.0");
parent.current && autoAnimate(parent.current)
})();
},[parent]);
return <div ref={parent}>
<h2 class="text-lg">{name}</h2>
{rows.map((row) => {
const firstOccur = !prevSet.has(row.Code);
return (
<div
key={row.Code}
class={[
"bg-white",
firstOccur ? "text-[#ff5454]" : "text-black",
].join(" ")}
>
<a href={`https://stockplus.com/m/stocks/KOREA-A${row.Code}`}>
{row.Name}
</a>
</div>
);
})}
</div>
}
function StockList({ data }: { data: PageCorpsInfo }) {
console.log("data");
const corpListByDate = data.corpListByDate;
const keys = Object.keys(corpListByDate).sort().reverse().slice(0, 5)
.reverse();
const sets = keys.map((x) => new Set(corpListByDate[x].map((y) => y.Code)));
//const rows = data.corpListbyDate;
return (
<div class="flex">
{keys.map((x, i) => {
const prevSet = i == 0 ? new Set<string>() : sets[i - 1];
const rows = corpListByDate[x];
return (
<StockListByDate key={x} name={x} prevSet={prevSet} rows={rows}></StockListByDate>
);
})}
</div>
);
}
type FilterInfoOption = {
list: {
items: CorpSimple[];
include: boolean;
}[];
otherwise: boolean;
};
function filterInfo(info: Coperation[], filterList: FilterInfoOption) {
const checkMap = new Map<string, boolean>();
for (const l of filterList.list) {
for (const i of l.items) {
checkMap.set(i.code, l.include);
}
}
return info.filter((x) => {
const v = checkMap.get(x.Code);
if (v === undefined) {
return filterList.otherwise;
} else {
return v;
}
});
}
export default function StockListUI(props: StockProps) {
const sig = useQuery<PageCorpsInfo>("/api/pages/" + props.pageName);
const sig = useAsync<[PageCorpsInfo, CorpSimple[], CorpSimple[]]>(async () => {
const res = await Promise.all([
fetch("/api/pages/" + props.pageName),
fetch("/api/kospi"),
fetch("/api/kosdaq"),
]);
const corpsInfo = await res[0].json() as PageCorpsInfo;
const kospi = await res[1].json();
const kosdaq = await res[2].json();
return [corpsInfo, kospi, kosdaq];
});
const viewKospi = useSignal(true);
const viewKosdaq = useSignal(false);
const viewOtherwise = useSignal(false);
return (
<div class="my-2">
<div class="flex gap-2">
<ToggleButton>Kospi</ToggleButton>
<ToggleButton>Kosdaq</ToggleButton>
<ToggleButton>Otherwise</ToggleButton>
<ToggleButton toggle={viewKospi}>Kospi</ToggleButton>
<ToggleButton toggle={viewKosdaq}>Kosdaq</ToggleButton>
<ToggleButton toggle={viewOtherwise}>Otherwise</ToggleButton>
</div>
<div class="flex gap-8 py-6 flex-col">
{sig.value.type == "loading"
? (new Array(20).fill(0).map((_) => (
<div class="animate-pulse bg-gray-300 p-2"></div>
)))
: <div>
{
sig.value.type == "error" ? (<div>
: (
<div>
{sig.value.type == "error"
? (
<div>
<p>File Loading Failed</p>
</div>) : <StockList data={sig.value.data}></StockList>
}
</div>}
</div>
)
: <StockList data={applyFilter(sig.value.data[0], sig.value.data[1], sig.value.data[2])}></StockList>}
</div>
)}
</div>
</div>
);
function applyFilter(data: PageCorpsInfo, kospi: CorpSimple[], kosdaq: CorpSimple[]): PageCorpsInfo{
const filter = getFilters(kospi,kosdaq);
return {
name: data.name,
description: data.description,
corpListByDate: mapValues(data.corpListByDate, (it: Coperation[])=>{
return filterInfo(it, filter);
})
}
}
function getFilters(kospi: CorpSimple[], kosdaq: CorpSimple[]): FilterInfoOption{
return {
otherwise: viewOtherwise.value,
list: [{
include: viewKospi.value,
items: kospi
},
{
include: viewKosdaq.value,
items: kosdaq
}
]
}
}
}

44
notebook.py Normal file
View File

@ -0,0 +1,44 @@
# %%
import matplotlib.pyplot as plt
# %%
import gen
# %%
dataStore = gen.DataStore()
stock = dataStore.getStockPrice("108320",250)
close = stock["CLOSE"]
d45 = close.loc[::-1].rolling(window=45).mean().dropna().loc[::-1]
rsi = gen.calc_rsi(close.loc[::-1],14).dropna().loc[::-1]
rsi.reset_index(drop = True, inplace = True)
# %%
# %%
krxCrops = dataStore.getAllKRXCorp()
krxCrops
# %%
krxCrops[0]
# %%
# %%
#%%time
lst = []
for entry in krxCrops:
data = dataStore.getStockPrice(entry.Code, 120)
lst.append(data)
print("a")
# %%
lst
# %%
#%%time
lst_mean = [ s["CLOSE"].mean() for s in lst]
# %%
len(krxCrops)
# %%
RANGE = 50
plt.plot(d45.iloc[:RANGE].loc[::-1])
plt.plot(close.iloc[:RANGE].loc[::-1])
plt.show()

View File

@ -36,19 +36,22 @@
macd가 아래로 내려가는 시점을 찾습니다. macd 는 5일선과 10일선으로 이루어지고
시그널을 구하기 위한 이동 평균은 4일입니다.
- name: 뭉침
description: 20 30 60 120 만난것 종가 5% 이내
description: d5, d20, d45, d60 만난것 종가 5% 이내
- name: 뭉침01
description: 20 30 60 120 만난것 종가 1% 이내
description: d5, d20, d45, d60 만난것 종가 1% 이내
- name: 뭉침03
description: 20 30 60 120 만난것 종가 3% 이내
- name: 뭉침 240선까지
description: 20 30 60 120 240 만난것 종가 5% 이내
description: d5, d20, d45, d60 만난것 종가 3% 이내
- name: 45일선 반등
description: 45일 선반등
- name: 뭉침5% 120선 상승
description: 뭉침5% 120선 상승
- name: 뭉침3% 120선 상승
description: 뭉침3% 120선 상승
- name: 뭉침1% 120선 상승
description: 뭉침1% 120선 상승
- name: 60일 10일 반등
description: 60일선이 10일 전보다 크면
- name: RSI 30 이하

View File

@ -17,7 +17,7 @@ export default function Pages(props: PageProps) {
height="128"
alt="stock graph"
/>
<h1>{props.params.name}</h1>
<h1 class="text-4xl">{props.params.name}</h1>
<StockList pageName={props.params.name}></StockList>
</div>
</div>

View File

@ -45,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@ -54,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 3,
"metadata": {},
"outputs": [
{
@ -63,7 +63,7 @@
"False"
]
},
"execution_count": 12,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
@ -74,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@ -83,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@ -92,16 +92,16 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"data = GetStockPriceFrom(db,\"042670\", 61)\n"
"data = GetStockPriceFrom(db,\"212310\", 61)\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
@ -110,7 +110,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
@ -119,7 +119,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
@ -128,7 +128,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"outputs": [
{
@ -173,54 +173,54 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2022-06-10</th>\n",
" <td>042670</td>\n",
" <td>6490</td>\n",
" <td>210</td>\n",
" <td>6670</td>\n",
" <td>6680</td>\n",
" <td>6470</td>\n",
" <td>1817916</td>\n",
" <th>2023-06-02</th>\n",
" <td>212310</td>\n",
" <td>2375</td>\n",
" <td>75</td>\n",
" <td>2205</td>\n",
" <td>2615</td>\n",
" <td>2205</td>\n",
" <td>19</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-06-09</th>\n",
" <td>042670</td>\n",
" <td>6700</td>\n",
" <td>110</td>\n",
" <td>6620</td>\n",
" <td>6750</td>\n",
" <td>6440</td>\n",
" <td>2623890</td>\n",
" <th>2023-06-01</th>\n",
" <td>212310</td>\n",
" <td>2300</td>\n",
" <td>35</td>\n",
" <td>2335</td>\n",
" <td>2645</td>\n",
" <td>2215</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-06-08</th>\n",
" <td>042670</td>\n",
" <td>6590</td>\n",
" <td>160</td>\n",
" <td>6820</td>\n",
" <td>6860</td>\n",
" <td>6580</td>\n",
" <td>2026670</td>\n",
" <th>2023-05-31</th>\n",
" <td>212310</td>\n",
" <td>2335</td>\n",
" <td>0</td>\n",
" <td>2340</td>\n",
" <td>2340</td>\n",
" <td>2335</td>\n",
" <td>145</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-06-07</th>\n",
" <td>042670</td>\n",
" <td>6750</td>\n",
" <td>150</td>\n",
" <td>6870</td>\n",
" <td>6990</td>\n",
" <td>6720</td>\n",
" <td>3234237</td>\n",
" <th>2023-05-30</th>\n",
" <td>212310</td>\n",
" <td>2335</td>\n",
" <td>190</td>\n",
" <td>2275</td>\n",
" <td>2790</td>\n",
" <td>2275</td>\n",
" <td>6245</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-06-03</th>\n",
" <td>042670</td>\n",
" <td>6900</td>\n",
" <td>440</td>\n",
" <td>6550</td>\n",
" <td>6940</td>\n",
" <td>6510</td>\n",
" <td>9983571</td>\n",
" <th>2023-05-26</th>\n",
" <td>212310</td>\n",
" <td>2525</td>\n",
" <td>30</td>\n",
" <td>2450</td>\n",
" <td>2780</td>\n",
" <td>2420</td>\n",
" <td>658</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
@ -233,54 +233,54 @@
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-21</th>\n",
" <td>042670</td>\n",
" <td>6770</td>\n",
" <td>120</td>\n",
" <td>6910</td>\n",
" <td>7030</td>\n",
" <td>6770</td>\n",
" <td>1314044</td>\n",
" <th>2023-03-13</th>\n",
" <td>212310</td>\n",
" <td>3190</td>\n",
" <td>100</td>\n",
" <td>3695</td>\n",
" <td>3695</td>\n",
" <td>2805</td>\n",
" <td>2967</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-18</th>\n",
" <td>042670</td>\n",
" <td>6890</td>\n",
" <td>200</td>\n",
" <td>6750</td>\n",
" <td>6890</td>\n",
" <td>6650</td>\n",
" <td>1207925</td>\n",
" <th>2023-03-10</th>\n",
" <td>212310</td>\n",
" <td>3290</td>\n",
" <td>15</td>\n",
" <td>3675</td>\n",
" <td>3675</td>\n",
" <td>3110</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-17</th>\n",
" <td>042670</td>\n",
" <td>6690</td>\n",
" <td>50</td>\n",
" <td>6790</td>\n",
" <td>6790</td>\n",
" <td>6670</td>\n",
" <td>1003575</td>\n",
" <th>2023-03-09</th>\n",
" <td>212310</td>\n",
" <td>3275</td>\n",
" <td>205</td>\n",
" <td>3800</td>\n",
" <td>3800</td>\n",
" <td>3220</td>\n",
" <td>467</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-16</th>\n",
" <td>042670</td>\n",
" <td>6640</td>\n",
" <td>60</td>\n",
" <td>6610</td>\n",
" <td>6680</td>\n",
" <td>6570</td>\n",
" <td>642939</td>\n",
" <th>2023-03-08</th>\n",
" <td>212310</td>\n",
" <td>3480</td>\n",
" <td>15</td>\n",
" <td>3460</td>\n",
" <td>3480</td>\n",
" <td>3460</td>\n",
" <td>289</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-15</th>\n",
" <td>042670</td>\n",
" <td>6580</td>\n",
" <td>260</td>\n",
" <td>6830</td>\n",
" <td>6840</td>\n",
" <td>6550</td>\n",
" <td>1776057</td>\n",
" <th>2023-03-07</th>\n",
" <td>212310</td>\n",
" <td>3495</td>\n",
" <td>235</td>\n",
" <td>3495</td>\n",
" <td>3500</td>\n",
" <td>3315</td>\n",
" <td>125</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
@ -288,24 +288,24 @@
"</div>"
],
"text/plain": [
" CODE CLOSE DIFF OPEN HIGH LOW VOLUME\n",
"DATE \n",
"2022-06-10 042670 6490 210 6670 6680 6470 1817916\n",
"2022-06-09 042670 6700 110 6620 6750 6440 2623890\n",
"2022-06-08 042670 6590 160 6820 6860 6580 2026670\n",
"2022-06-07 042670 6750 150 6870 6990 6720 3234237\n",
"2022-06-03 042670 6900 440 6550 6940 6510 9983571\n",
"... ... ... ... ... ... ... ...\n",
"2022-03-21 042670 6770 120 6910 7030 6770 1314044\n",
"2022-03-18 042670 6890 200 6750 6890 6650 1207925\n",
"2022-03-17 042670 6690 50 6790 6790 6670 1003575\n",
"2022-03-16 042670 6640 60 6610 6680 6570 642939\n",
"2022-03-15 042670 6580 260 6830 6840 6550 1776057\n",
" CODE CLOSE DIFF OPEN HIGH LOW VOLUME\n",
"DATE \n",
"2023-06-02 212310 2375 75 2205 2615 2205 19\n",
"2023-06-01 212310 2300 35 2335 2645 2215 16\n",
"2023-05-31 212310 2335 0 2340 2340 2335 145\n",
"2023-05-30 212310 2335 190 2275 2790 2275 6245\n",
"2023-05-26 212310 2525 30 2450 2780 2420 658\n",
"... ... ... ... ... ... ... ...\n",
"2023-03-13 212310 3190 100 3695 3695 2805 2967\n",
"2023-03-10 212310 3290 15 3675 3675 3110 9\n",
"2023-03-09 212310 3275 205 3800 3800 3220 467\n",
"2023-03-08 212310 3480 15 3460 3480 3460 289\n",
"2023-03-07 212310 3495 235 3495 3500 3315 125\n",
"\n",
"[61 rows x 7 columns]"
]
},
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
@ -316,28 +316,190 @@
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
"2022-06-03 175508\n",
"2022-06-02 350113\n",
"2022-05-31 276819\n",
"2022-05-30 191087\n",
"2022-05-27 392051\n",
" ... \n",
"2022-03-15 2701677\n",
"2022-03-14 4436719\n",
"2022-03-11 997048\n",
"2022-03-10 1754702\n",
"2022-03-08 878964\n",
"2023-06-02 2374.0\n",
"2023-06-01 2398.0\n",
"2023-05-31 2404.0\n",
"2023-05-30 2434.0\n",
"2023-05-26 2447.0\n",
"2023-05-25 2447.0\n",
"Name: CLOSE, dtype: float64"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"close = stock[\"CLOSE\"]\n",
"d5 = stock[\"CLOSE\"].iloc[:10].loc[::-1].rolling(window=5\n",
" ).mean().dropna().loc[::-1]\n",
"d5"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
"2023-06-02 88.487287\n",
"2023-06-01 103.778611\n",
"2023-05-31 97.365292\n",
"2023-05-30 93.834962\n",
"2023-05-26 80.202868\n",
"2023-05-25 80.202868\n",
"Name: CLOSE, dtype: float64"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dstd5 = close.iloc[:10].loc[::-1].rolling(window=5).std().dropna().loc[::-1]\n",
"dstd5"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
"2023-06-01 2398.0\n",
"2023-05-31 2404.0\n",
"Name: CLOSE, dtype: float64"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d5[[1,2]]"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(50.04, 0.2, 50.44, True)"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = 51\n",
"arr = np.array([50]* 24 + [a])\n",
"m = arr.mean()\n",
"std = arr.std(ddof=1)\n",
"m, std , m + 2*std, m+2*std < a"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10.0"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(a-50)/5"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"59.082092668956086"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"krx.__len__() * ((100-95.4499736104)/100)*0.5"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
"2023-05-22 27\n",
"2023-05-19 403\n",
"2023-05-18 1\n",
"2023-05-17 5\n",
"2023-05-16 3711\n",
" ... \n",
"2023-02-28 1017\n",
"2023-02-27 799\n",
"2023-02-24 12\n",
"2023-02-23 688\n",
"2023-02-22 4\n",
"Name: VOLUME, Length: 61, dtype: int64"
]
},
"execution_count": 52,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
@ -347,6 +509,26 @@
"volume"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'2023-05-22'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock.index[0]"
]
},
{
"cell_type": "code",
"execution_count": 62,
@ -458,7 +640,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
@ -477,20 +659,77 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"def isRelativeDiffLessThan(a:pd.Series,b:pd.Series, threshold: float,nday:int) -> bool:\n",
" return (a.iloc[nday] - b.iloc[nday]) / b.iloc[nday] < threshold"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"def every(f, xs):\n",
" for x in xs:\n",
" if not f(x):\n",
" return False\n",
" return True"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"evert\n",
"6236.0 6290 -54.0\n"
]
},
{
"data": {
"text/plain": [
"-0.008585055643879173"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = [d5, d10, d20, d30, d60]\n",
"if every(lambda i: isRelativeDiffLessThan(i,close,0.05,nday), a):\n",
" print(\"evert\")"
"if every(lambda i: isRelativeDiffLessThan(i,close,0.05,0), a):\n",
" print(\"evert\")\n",
"print(d5.iloc[0] , close.iloc[0],d5.iloc[0] - close.iloc[0])\n",
"(d5.iloc[0] - close.iloc[0]) / close.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-0.1876921038685744"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(d60.iloc[0] - close.iloc[0])/close.iloc[0]"
]
},
{