Harigami
ログイン
Harigamiは、ログイン不要のコード共有サービスです。コードの投稿後に発行されるURLでコードを共有できます。
PythonやRubyなど一部の言語は、投稿後にオンラインで実行することもできます。
誰でも無料で使えて、広告もありません。コードレビューやスニペットの代わりに使ってみてください。


詳細設定
+
死にかけボンバイエ タイトルなし
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
  • 0
  • 1
anonymous タイトルなし
Python
FROM tensorflow/tensorflow:latest-gpu-py3-jupyter

USER root
RUN apt-get update && apt-get install fonts-ipaexfont libglib2.0-0 git gcc -y \
&& apt-get install libsm-dev libxrender-dev libxext-dev ffmpeg -y

RUN mkdir -p /opt/local/work \
&& chown -R ${NB_USER}. /opt/local/work

USER $NB_USER
WORKDIR /opt/local/work
COPY requirements.lock .
#RUN pip install --upgrade pip
RUN pip install -r requirements.lock
#&& conda update -n base conda \
#&& conda install --yes --channel conda-forge jupyter_contrib_nbextensions
#&& pip install -r requirements.lock
#&& conda update -n base conda \
#&& conda install --yes --channel conda-forge jupyter_contrib_nbextensions

#FROM nvidia/cuda:10.1-cudnn7-devel
  • 0
  • 1
anonymous タイトルなし
JavaScript
function removeAllFromState(state, name) {
    const options = resolveOption(name);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) continue;
        const rootBucket = state[realName];
        const keys = index.keys;
        for(const id in source) {
            removeIndexMulti(source[id], id, rootBucket, keys);
        }
    }

    Vue.delete(state, options.sourceName);
}
  • 0
  • 0
anonymous タイトルなし
JavaScript
<template>
    <div>
            <slot/>
            <transition name="fade">
            <div class="text-xs-center" v-show="refreshing">
                <span class="progress-bg">
            <v-progress-circular
                indeterminate
                color="green"
                size="24"
                width="3"
            />
                </span>
            </div>
            </transition>
    </div>
</template>

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
@Component({})
export default class Refreshable extends Vue {
    @Prop() refreshing?: boolean;
}

</script>

<style scoped lang="scss">
.text-xs-center {
    z-index: 2;
    vertical-align: middle;
    position: absolute;
    top: 4rem;
    left: 0;
    width: 100%;
}

.progress-bg {
    display: inline-flex;
    background-color: #fff;
    width: 50px;
    height: 50px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    border-radius: 25px;
    box-shadow:0px 0px 10px rgba(0,0,0,0.25);
}
.fade-enter-active, .fade-leave-active {
  transition: opacity .25s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}
</style>

  • 0
  • 1
anonymous タイトルなし
JavaScript
function resolveOption(optname) {
    const option = opts[optname];
    if(!option.sourceName) option.sourceName = optname;
    if(!option.primary) option.primary = 'id';
    if(!option.prefix) option.prefix = optname.toLowerCase();
    return option;
}

function addValueToState(state, optname, value) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) Vue.set(state, options.sourceName, {});

    const source = state[options.sourceName];

    // Add to source
    Vue.set(source, value[options.primary], value);

    // build index
    addIndexToState(state, optname, value[options.primary]);
}

function addIndexToState(state, optname, id) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        buildIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}

function removeIndexMulti(v, id, bucket, keys, i = 0) {
    const key = v[keys[i]];
    if(keys.length-1 == i) {
        bucket[key] = bucket[key].filter(x => x != id);
    }
    else {
        removeIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function removeValueFromState(state, optname, id) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    // remove for each index
    removeIndexFromState(state, optname, id);

    // remove from source
    Vue.delete(source, id);
}

function removeIndexFromState(state, optname, id) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        removeIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}
  • 0
  • 1
anonymous タイトルなし
Python
//@version=3
study("Hull cross and ATR", shorttitle="H&ATR", overlay=true)
keh=input(title="Hull Length",type=integer,defval=52)
length = input(title="ATR Length", defval=46, minval=1)
smoothing = input(title="ATR Smoothing", defval="WMA", options=["RMA", "SMA", "EMA", "WMA"])
p=input(ohlc4,type=source,title="Price data")
n2ma=2*wma(p,round(keh/2))
nma=wma(p,keh)
diff=n2ma-nma
sqn=round(sqrt(keh))
n2ma1=2*wma(p[1],round(keh/2))
nma1=wma(p[1],keh)
diff1=n2ma1-nma1
sqn1=round(sqrt(keh))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
ma_function(source, length) => 
    if smoothing == "RMA"
        rma(p, length)
    else
        if smoothing == "SMA"
            sma(p, length)
        else
            if smoothing == "EMA"
                ema(p, length)
            else
                wma(p, length)
plot(ma_function(tr(true), length), title = "ATR", color=#00000000, transp=50)
exitLong = n1<n2
exitShort = n1>n2
longCondition = ma_function(tr(true), length)<p and p>p[length] and n1>n2
shortCondition = ma_function(tr(true), length)>p and p<p[length] and n1<n2

_state = 0
_prev  = nz(_state[1])
_state := _prev
if _prev == 0
    if longCondition 
        _state := 1
    if shortCondition 
        _state := 2
if _prev == 1
    if exitLong
        _state := 0
if _prev == 2
    if exitShort
        _state := 0
_bLongEntry  = (_state == 1 and _prev == 0)
_bShortEntry = (_state == 2 and _prev == 0)
_bLclose  = (_state == 0 and _prev == 1)
_bSclose   = (_state == 0 and _prev == 2)

alertcondition(_bLongEntry, title="BUY", message="Buy")
alertcondition(_bShortEntry, title="SELL", message="Sell")
alertcondition(_bLclose or _bSclose, title="CLOSE", message="Close")
bgcolor(_bLongEntry?lime:na, transp=30)
bgcolor(_bShortEntry?red:na, transp=30)
bgcolor(_bLclose or _bSclose?yellow:na, transp=30)
  • 0
  • 1
anonymous タイトルなし
Python
//@version=3
strategy("Hull cross and ATR", shorttitle="H&ATR", overlay=true)
keh=input(title="Hull Length",type=integer,defval=52)
length = input(title="ATR Length", defval=46, minval=1)
smoothing = input(title="ATR Smoothing", defval="WMA", options=["RMA", "SMA", "EMA", "WMA"])
p=input(ohlc4,type=source,title="Price data")
n2ma=2*wma(p,round(keh/2))
nma=wma(p,keh)
diff=n2ma-nma
sqn=round(sqrt(keh))
n2ma1=2*wma(p[1],round(keh/2))
nma1=wma(p[1],keh)
diff1=n2ma1-nma1
sqn1=round(sqrt(keh))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
ma_function(source, length) => 
    if smoothing == "RMA"
        rma(p, length)
    else
        if smoothing == "SMA"
            sma(p, length)
        else
            if smoothing == "EMA"
                ema(p, length)
            else
                wma(p, length)
plot(ma_function(tr(true), length), title = "ATR", color=black, transp=50)
closelong = n1<n2
if (closelong)
    strategy.close("buy")
closeshort = n1>n2
if (closeshort)
    strategy.close("sell")
if (ma_function(tr(true), length)<p and p>p[length] and n1>n2)
    strategy.entry("buy", strategy.long, comment="BUY")
if (ma_function(tr(true), length)>p and p<p[length] and n1<n2)
    strategy.entry("sell", strategy.short, comment="SELL")
  • 0
  • 0
anonymous タイトルなし
JavaScript
function addValueToState(state, options, value) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    // Add to source
    Vue.set(source, value[options.primary], value);

    // build index
    addIndexToState(state, options, value[options.primary]);
}

function addIndexToState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        buildIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}

function removeIndexMulti(v, id, bucket, keys, i = 0) {
    const key = v[keys[i]];
    console.log(bucket);
    if(keys.length-1 == i) {
        bucket[key] = bucket[key].filter(x => x != id);
    }
    else {
        removeIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function removeValueFromState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    // remove for each index
    removeIndexFromState(state, options, id);

    // remove from source
    Vue.delete(source, id);
}

function removeIndexFromState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        removeIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}
  • 0
  • 1
anonymous タイトルなし
JavaScript
const shiftOptions: EntityOptions = {
    sourceName: 'shifts',
    primary: 'id',
    prefix: 'shift',
    indexes: {
        'idx1': { keys: [ 'branch_id', 'yearmonth', 'day' ] }
    }
}


function buildIndexMulti(v, id, bucket, keys, i = 0) {
    if(keys.length == i) {
        Vue.set(bucket, bucket.length, id);
    }
    else {
        const key = v[keys[i]]
        if(!bucket[key]) Vue.set(bucket, key, keys.length - i >= 2 ? {} : []);
        buildIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function addArrayToState(state, options, array) {
    if(!state[options.sourceName]) Vue.set(state, options.sourceName, {});

    const source = state[options.sourceName];
    const primary = options.primary;

    // build source
    for(const v of array) {
        // build source
        Vue.set(source, v[options.primary], v);
    }

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        for(const v of array) {
            buildIndexMulti(v, v[primary], rootBucket, keys);
        }
    }
}
  • 0
  • 1
anonymous タイトルなし
JavaScript
const MyEventEmitter = function() {
    this.callbackPool = {};
}

MyEventEmitter.prototype.on = function(type, callback) {
    this.callbackPool[type] = callback;
}

MyEventEmitter.prototype.emit = function(type, arg) {
    const sliced = [];
    for(let i = 1; i < arguments.length; i++) sliced.push(arguments[i]);
    if(this.callbackPool) this.callbackPool[type].apply(undefined, sliced);
}
  • 0
  • 0