diff --git a/README.md b/README.md index 159e4fc46dc18732bedd88ec6c170672c4709ab9..17b59ea288346cb36585eb07d80ff3726a6151e2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# Aro +# Aro cccc A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. diff --git a/ZfAbsMean.py b/ZfAbsMean.py new file mode 100644 index 0000000000000000000000000000000000000000..77b654bc45a3f2d71adcf2522704db9ed612445a --- /dev/null +++ b/ZfAbsMean.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +""" +中性策略框架 | 邢不行 | 2024分享会 +author: 邢不行 +微信: xbx6660 +""" +import numpy as np + +""" +波动因子 +""" +def signal(*args): + df = args[0] + n = args[1] + factor_name = args[2] + + df['均价'] = (df['close'] + df['high'] + df['low']) / 3 + + df['涨跌幅'] = df['均价'].pct_change() + df['振幅'] = (df['high'] - df['low']) / df['open'] + df['振幅'] = np.where(df['涨跌幅'] > 0, df['振幅'], 0) + df['振幅均值'] = df['振幅'].rolling(n, min_periods=1).mean() + + df[factor_name] = df['振幅均值'].rolling(n, min_periods=1).rank(ascending=True, pct=True) + + return df diff --git a/src/main.zig b/src/main.zig index 19935e6d03bbdb12b79d8093423ae9ce43fbc43a..cd0c05632289ba89802c4d7f8ec40263555aa09f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,6 +1,4 @@ const std = @import("std"); -const Allocator = mem.Allocator; -const mem = std.mem; const process = std.process; const aro = @import("aro"); const Compilation = aro.Compilation; @@ -8,16 +6,22 @@ const Driver = aro.Driver; const Toolchain = aro.Toolchain; const assembly_backend = @import("assembly_backend"); -var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; +fn handleOutOfMemory(fast_exit: bool) u8 { + std.debug.print("out of memory\n", .{}); + if (fast_exit) process.exit(1); + return 1; +} -pub fn main() u8 { - const gpa = if (@import("builtin").link_libc) - std.heap.raw_c_allocator - else - general_purpose_allocator.allocator(); - defer if (!@import("builtin").link_libc) { - _ = general_purpose_allocator.deinit(); +fn handleError(fast_exit: bool, er: anyerror) u8 { + return switch (er) { + error.OutOfMemory => handleOutOfMemory(fast_exit), }; +} + +pub fn main() u8 { + const link_libc = @import("builtin").link_libc; + const gpa = if (link_libc) std.heap.raw_c_allocator else std.heap.GeneralPurposeAllocator(.{}).allocator(); + defer if (!link_libc) _ = std.heap.GeneralPurposeAllocator(.{}).deinit(); var arena_instance = std.heap.ArenaAllocator.init(gpa); defer arena_instance.deinit(); @@ -25,46 +29,26 @@ pub fn main() u8 { const fast_exit = @import("builtin").mode != .Debug; - const args = process.argsAlloc(arena) catch { - std.debug.print("out of memory\n", .{}); - if (fast_exit) process.exit(1); - return 1; - }; + const args = process.argsAlloc(arena) catch handleError(fast_exit, @errorFromAny(error.OutOfMemory)); - const aro_name = std.fs.selfExePathAlloc(gpa) catch { - std.debug.print("unable to find Aro executable path\n", .{}); - if (fast_exit) process.exit(1); - return 1; - }; + const aro_name = std.fs.selfExePathAlloc(gpa) catch handleError(fast_exit, @errorFromAny(error.OutOfMemory)); defer gpa.free(aro_name); - var comp = Compilation.initDefault(gpa, std.fs.cwd()) catch |er| switch (er) { - error.OutOfMemory => { - std.debug.print("out of memory\n", .{}); - if (fast_exit) process.exit(1); - return 1; - }, - }; + var comp = Compilation.initDefault(gpa, std.fs.cwd()) catch |er| handleError(fast_exit, er); defer comp.deinit(); - var driver: Driver = .{ .comp = &comp, .aro_name = aro_name }; - defer driver.deinit(); + var driver = Driver{ .comp = &comp, .aro_name = aro_name }; + var toolchain = Toolchain{ .driver = &driver, .arena = arena, .filesystem = .{ .real = comp.cwd } }; - var toolchain: Toolchain = .{ .driver = &driver, .arena = arena, .filesystem = .{ .real = comp.cwd } }; - defer toolchain.deinit(); - - driver.main(&toolchain, args, fast_exit, assembly_backend.genAsm) catch |er| switch (er) { - error.OutOfMemory => { - std.debug.print("out of memory\n", .{}); - if (fast_exit) process.exit(1); - return 1; - }, - error.FatalError => { + driver.main(&toolchain, args, fast_exit, assembly_backend.genAsm) catch |er| { + handleError(fast_exit, er); + if (@errorIntoBool(er)) { driver.renderErrors(); if (fast_exit) process.exit(1); return 1; - }, + } }; + if (fast_exit) process.exit(@intFromBool(comp.diagnostics.errors != 0)); return @intFromBool(comp.diagnostics.errors != 0); -} +} \ No newline at end of file