Tuesday, 29 October 2019

Python Programming for Finance 1

#powerShell
pip install pandas pandas-datareader matplotlib beautifulsoup4 scikit-learn

#pycharm file->settings->project->interpreter->install libraries

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web

style.use('ggplot')

start = dt.datetime(2011, 1, 1)
end = dt.datetime(2019, 10, 30)

df = web.DataReader('TSLA', 'yahoo', start, end)
print(df.tail(6))

-------------------------------
#log
                  High         Low        Open       Close    Volume   Adj Close
Date
2019-10-23  256.140015  251.350006  254.500000  254.679993   5261100  254.679993
2019-10-24  304.929993  289.200012  298.369995  299.679993  29720900  299.679993
2019-10-25  330.000000  296.109985  297.720001  328.130005  29982400  328.130005
2019-10-28  340.839996  322.600006  327.540009  327.709991  18860900  327.709991
2019-10-29  324.299988  314.750000  319.989990  316.220001  12673300  316.220001
2019-10-30  318.790009  309.970001  313.000000  315.010010   9637000  315.010010

-------------------------------
#log print(df.head())

                 High        Low   Open      Close   Volume  Adj Close
Date
2011-01-03  27.000000  25.900000  26.84  26.620001  1283000  26.620001
2011-01-04  26.950001  26.020000  26.66  26.670000  1187400  26.670000
2011-01-05  26.900000  26.190001  26.48  26.830000  1446700  26.830000
2011-01-06  28.000000  26.809999  26.83  27.879999  2061200  27.879999
2011-01-07  28.580000  27.900000  28.00  28.240000  2247900  28.240000

reference:
https://www.youtube.com/watch?v=2BrpKpWwT2A&list=PLQVvvaa0QuDcOdF96TBtRtuQksErCEBYZ&index=1

Monday, 28 October 2019

react native zoom view


original

zoom in to see license plate

pan

zoom out and pan

zoom out

furthest

npm install @dudigital/react-native-zoomable-view

import React from 'react';
import { View, Image, Text, StyleSheet } from 'react-native';
import ReactNativeZoomableView from '@dudigital/react-native-zoomable-view/src/ReactNativeZoomableView';

export default class App extends React.Component {

  render() {
    return (
      <View style={{ flex: 1 }}>
        <ReactNativeZoomableView
          maxZoom={1.5}
          minZoom={0.5}
          zoomStep={0.5}
          initialZoom={1}
          bindToBorders={true}

          style={{

          }}
        >
          <View style={{ flex: 1, justifyContent: "center" }}>
            <View style={{ alignItems: 'center' }}><Text style={{ fontSize: 30 }}>Content</Text></View>
            <Image style={{ width: null, height: '90%' }}
              source={require('./img/2R.jpg')}
              resizeMode="stretch" />
            <View style={{ alignItems: 'center' }}><Text style={{ fontSize: 30 }}>Content</Text></View>
          </View>
        </ReactNativeZoomableView>
      </View>
    );
  }
}

reference:
https://github.com/DuDigital/react-native-zoomable-view
https://wall.alphacoders.com/big.php?i=953683

Saturday, 26 October 2019

react native swiper horizontal






React native doesn't have any transform origin property yet. have to use translate to move rotation center to top left corner of screen, After rotation is done, shift view again to cover screen.

import React, { Component } from 'react'
import { Dimensions, ImageBackground, StyleSheet, Text, View } from 'react-native'
import Swiper from 'react-native-swiper'

const styles = StyleSheet.create({
  slide: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  text: {
    color: '#fff',
    fontSize: 30,
    fontWeight: 'bold'
  }
})

export default class SwiperComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      height: null,
      width: null,
    };
  }

  componentWillMount() {
    //swap screen height and width after rotation
    let { height, width } = Dimensions.get('window');
    this.setState({
      width: parseInt(height),
      height: parseInt(width)
    })
  }

  render() {

    console.log(this.state.height, this.state.width)
    return (

      <View style={{
        height: this.state.height,
        width: this.state.width,
        translateX: -this.state.width / 2,
        translateY: -this.state.height / 2,
        transform: [{ rotate: '90deg' }],
        top: this.state.width / 2,
        left: this.state.height / 2,
      }}>

        <Swiper showsButtons={true}>
          <ImageBackground source={require('./img/1.jpg')}
            resizeMode='stretch'
            style={{ ...styles.slide, width: '100%', height: '100%' }}>
            <Text style={styles.text}>Hello Swiper</Text>
          </ImageBackground>
          <ImageBackground source={require('./img/2.jpg')}
            resizeMode='stretch'
            style={{ ...styles.slide, width: '100%', height: '100%' }}>
            <Text style={styles.text}>Beautiful</Text>
          </ImageBackground>
          <ImageBackground source={require('./img/3.jpg')}
            resizeMode='stretch'
            style={{ ...styles.slide, width: '100%', height: '100%' }}>
            <Text style={styles.text}>And Simple</Text>
          </ImageBackground>
        </Swiper>
      </View>
    )
  }
}


reference:
https://chuanshuoge2.blogspot.com/2019/10/react-native-swiper.html
https://stackoverflow.com/questions/46303736/make-dimension-relative-to-another-in-react-native
https://stackoverflow.com/questions/35050774/how-can-i-make-text-vertical-rotated-90-deg-in-react-native
https://stackoverflow.com/questions/52561376/react-native-transform-origin

react native swiper




npm i react-native-swipe

import React, { Component } from 'react'
import { ImageBackground, StyleSheet, Text, View } from 'react-native'
import Swiper from 'react-native-swiper'

const styles = StyleSheet.create({
  wrapper: {},
  slide: {
    justifyContent: 'center',
    alignItems: 'center',
  },
  text: {
    color: '#fff',
    fontSize: 30,
    fontWeight: 'bold'
  }
})

export default class SwiperComponent extends Component {
  render() {
    return (
      <Swiper style={styles.wrapper} showsButtons={true}>
        <ImageBackground source={require('./img/1.jpg')}
          resizeMode='cover'
          style={{ ...styles.slide, width: '100%', height: '100%' }}>
          <Text style={styles.text}>Hello Swiper</Text>
        </ImageBackground>
        <ImageBackground source={require('./img/2.jpg')}
          resizeMode='cover'
          style={{ ...styles.slide, width: '100%', height: '100%' }}>
          <Text style={styles.text}>Beautiful</Text>
        </ImageBackground>
        <ImageBackground source={require('./img/3.jpg')}
          resizeMode='cover'
          style={{ ...styles.slide, width: '100%', height: '100%' }}>
          <Text style={styles.text}>And Simple</Text>
        </ImageBackground>
      </Swiper>
    )
  }
}


reference:
https://github.com/leecade/react-native-swiper
https://github.com/leecade/react-native-swiper/blob/master/examples/components/Swiper/index.js
https://facebook.github.io/react-native/docs/images.html#background-image-via-nesting

设计师把家变成了魔方