other changes
This commit is contained in:
62
testy/domfreq.py
Normal file
62
testy/domfreq.py
Normal file
@ -0,0 +1,62 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy.fft import fft
|
||||
|
||||
# Define the sampling frequency and time vector
|
||||
fs = 500 # Sampling frequency
|
||||
t = np.arange(0, 1, 1/fs) # Time vector
|
||||
|
||||
# Define the frequencies
|
||||
f1 = 5 # Frequency that occurs most often but with lower amplitude
|
||||
f2 = 20 # Frequency with the highest amplitude
|
||||
|
||||
# Creating the individual signals
|
||||
signal_f1 = 0.5 * np.sin(2 * np.pi * f1 * t) # Signal with frequency f1
|
||||
signal_f2 = 2 * np.sin(2 * np.pi * f2 * t) # Signal with frequency f2
|
||||
|
||||
# Composite signal
|
||||
signal = signal_f1 + signal_f2
|
||||
|
||||
# Performing a Fourier Transform
|
||||
freq = np.fft.fftfreq(len(t), 1/fs)
|
||||
fft_values = fft(signal)
|
||||
|
||||
# Plotting all the signals and the frequency spectrum
|
||||
plt.figure(figsize=(14, 10))
|
||||
|
||||
# Plot 1: Composite Signal
|
||||
plt.subplot(4, 1, 1)
|
||||
plt.plot(t, signal)
|
||||
plt.title('Composite Signal (f1 + f2)')
|
||||
plt.xlabel('Time [s]')
|
||||
plt.ylabel('Amplitude')
|
||||
|
||||
# Plot 2: Frequency f1 Signal
|
||||
plt.subplot(4, 1, 2)
|
||||
plt.plot(t, signal_f1)
|
||||
plt.title('Individual Frequency f1 Signal')
|
||||
plt.xlabel('Time [s]')
|
||||
plt.ylabel('Amplitude')
|
||||
|
||||
# Plot 3: Frequency f2 Signal
|
||||
plt.subplot(4, 1, 3)
|
||||
plt.plot(t, signal_f2)
|
||||
plt.title('Individual Frequency f2 Signal')
|
||||
plt.xlabel('Time [s]')
|
||||
plt.ylabel('Amplitude')
|
||||
|
||||
# Plot 4: Frequency Spectrum
|
||||
plt.subplot(4, 1, 4)
|
||||
plt.plot(freq, np.abs(fft_values))
|
||||
plt.title('Frequency Spectrum of Composite Signal')
|
||||
plt.xlabel('Frequency [Hz]')
|
||||
plt.ylabel('Amplitude')
|
||||
plt.xlim([0, 30])
|
||||
|
||||
# Highlighting the dominant frequencies in the spectrum
|
||||
plt.axvline(x=f1, color='green', linestyle='--', label='Frequency f1')
|
||||
plt.axvline(x=f2, color='red', linestyle='--', label='Frequency f2')
|
||||
|
||||
plt.legend()
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
28
testy/getlastcalendardate.py
Normal file
28
testy/getlastcalendardate.py
Normal file
@ -0,0 +1,28 @@
|
||||
from alpaca.data.historical import CryptoHistoricalDataClient, StockHistoricalDataClient
|
||||
from alpaca.data.requests import CryptoLatestTradeRequest, StockLatestTradeRequest, StockLatestBarRequest, StockTradesRequest, StockBarsRequest
|
||||
from alpaca.data.enums import DataFeed
|
||||
from config import API_KEY, SECRET_KEY, MAX_BATCH_SIZE
|
||||
import datetime
|
||||
import time
|
||||
from alpaca.data import Quote, Trade, Snapshot, Bar
|
||||
from alpaca.data.models import BarSet, QuoteSet, TradeSet
|
||||
from alpaca.data.timeframe import TimeFrame
|
||||
# import mplfinance as mpf
|
||||
import pandas as pd
|
||||
from rich import print
|
||||
from v2realbot.utils.utils import zoneNY
|
||||
from v2realbot.config import ACCOUNT1_PAPER_API_KEY, ACCOUNT1_PAPER_SECRET_KEY
|
||||
from alpaca.trading.requests import GetCalendarRequest
|
||||
from alpaca.trading.client import TradingClient
|
||||
|
||||
parametry = {}
|
||||
|
||||
clientTrading = TradingClient(ACCOUNT1_PAPER_API_KEY, ACCOUNT1_PAPER_SECRET_KEY, raw_data=False)
|
||||
|
||||
#get previous days bar
|
||||
|
||||
datetime_object_from = datetime.datetime(2023, 10, 11, 4, 0, 00, tzinfo=datetime.timezone.utc)
|
||||
datetime_object_to = datetime.datetime(2023, 10, 16, 16, 1, 00, tzinfo=datetime.timezone.utc)
|
||||
calendar_request = GetCalendarRequest(start=datetime_object_from,end=today)
|
||||
cal_dates = clientTrading.get_calendar(calendar_request)
|
||||
print(cal_dates)
|
||||
34
testy/histogramnumpy.py
Normal file
34
testy/histogramnumpy.py
Normal file
@ -0,0 +1,34 @@
|
||||
import numpy as np
|
||||
|
||||
data = np.array([1,2,3,4,3,2,4,7,8,4,3,0,0,0,0,9,9,9,11,23,2,3,4,29,23])
|
||||
|
||||
counts, bin_edges = np.histogram(data, bins=4)
|
||||
# returns a tuple containing two arrays:
|
||||
# counts: An array containing the number of data points in each bin.
|
||||
# bin_edges: An array containing the edges of each bin.
|
||||
#(array([10, 6, 0, 1]), array([ 1. , 6.5, 12. , 17.5, 23. ]))
|
||||
print(counts, bin_edges)
|
||||
|
||||
edge_from = bin_edges[3]
|
||||
edge_to = bin_edges[4]
|
||||
print(edge_from)
|
||||
print(edge_to)
|
||||
print("test where", data[np.where((edge_from<data) & (data<edge_to))])
|
||||
|
||||
ctvrty_bin = [datum for datum in data if edge_from <= datum <= edge_to]
|
||||
|
||||
print(np.mean(ctvrty_bin))
|
||||
|
||||
#print(histo[0][-2])
|
||||
|
||||
bins = 4
|
||||
mean_of_4th_bin = np.mean(data[np.where(np.histogram(data, bins)[1][3] <= data)[0]])
|
||||
# print(mean_of_4th_bin)
|
||||
# print(mean_of_fourth_bucket)
|
||||
|
||||
|
||||
|
||||
|
||||
# Print the data from the 3rd bin using a list comprehension
|
||||
|
||||
#print([datum for datum in data if bin_edges[2] <= datum < bin_edges[3]])
|
||||
14
testy/numpylistmutability.py
Normal file
14
testy/numpylistmutability.py
Normal file
@ -0,0 +1,14 @@
|
||||
import numpy as np
|
||||
from array import array
|
||||
|
||||
# Original list
|
||||
puvodni = array('i', [1, 2, 3, 4])
|
||||
|
||||
# Create a NumPy array using the original list
|
||||
numpied = np.array(puvodni)
|
||||
|
||||
# Now, if puvodni changes, numpied will be updated as well
|
||||
puvodni.append(5)
|
||||
|
||||
# Check the updated numpied array
|
||||
print(numpied)
|
||||
25
testy/picklequeue.py
Normal file
25
testy/picklequeue.py
Normal file
@ -0,0 +1,25 @@
|
||||
import queue
|
||||
import msgpack
|
||||
# Creating the original queue
|
||||
original_queue = queue.Queue()
|
||||
new_queue = queue.Queue()
|
||||
|
||||
# Adding elements to the original queue
|
||||
original_queue.put(5)
|
||||
original_queue.put(10)
|
||||
original_queue.put(15)
|
||||
|
||||
# Pickling the queue
|
||||
pickled_queue = msgpack.packb(original_queue)
|
||||
|
||||
# Unpickling the queue
|
||||
unpickled_queue = msgpack.unpackb(pickled_queue)
|
||||
# Pickling the queue
|
||||
new_queue.queue = unpickled_queue.queue
|
||||
|
||||
|
||||
print(new_queue)
|
||||
|
||||
# Checking the contents of the new queue
|
||||
while not new_queue.empty():
|
||||
print(new_queue.get())
|
||||
Reference in New Issue
Block a user